Google Analytics Utilities for Cloud uses Cloud Functions to accomplish specific tasks. Please follow the steps below to implement the utilities you want.
All of these utilities require that the Analytics Admin API be enabled in your Cloud project.
The linker utility addresses the following use cases:
- Linking Google Ads
- Linking DV360
- Sending DV360 link proposals
The linker utility relies on a single Google Cloud Function to loop through a list of link settings. These settings must be uploaded to a Google Cloud Storage bucket as a CSV file of your choosing. Upon completion, the function will write a results CSV file to an output storage bucket of your choosing.
If it takes longer than one hour for the function to complete, it will upload a CSV file with the remaining settings to the input bucket automatically to kick off another function until all of the requests have been attempted.
The following steps describe how to set up the linker utility.
- Create a service account in Google Cloud by navigating to IAM & Admin > Service Accounts
- Give the service account a name and grant it the following access:
- Storage Admin
- Eventarc Event Receiver
- Cloud Run Invoker
- Save the service account.
- Navigate to APIs & Services > OAuth consent screen.
- Create an internal OAuth consent screen.
- Enter an app name. For the purposes of this guide, we will use GA Utilities.
- Enter a support email.
- Enter developer contact information.
- Add the following scope:
- Save the consent screen settings.
- Navigate to APIs & Services > Credentials.
- Create an OAuth Client ID credential.
- Select a Web Application type.
- Give it a recognizable name.
- Add https://developers.google.com as an authorized JavaScript origin.
- Add https://developers.google.com/oauthplayground as an authorized redirect URI.
- Make note of your client ID and client secret.
- Navigate to https://developers.google.com/oauthplayground. NOTE: Please make sure that the user with the correct access to Google Analytics, Google Ads, and DV360 completes the following steps.
- From the list of APIs, select Google Analytics Admin API v1Beta and select https://www.googleapis.com/auth/analytics.edit.
- In the upper righthand corner, click on the gear icon, and enter the following settings:
- OAuth flow: server-side
- Oath endpoints: Google
- Authorization endpoint: https://accounts.google.com/o/oauth2/v2/auth
- Token endpoint: https://oauth2.googleapis.com/token
- Access token location: Authorization header w/ Bearer prefix
- Access type: Offline
- Check "Use your own OAuth Credentials"
- Enter your OAuth client ID and client secret
- After entering the OAuth 2.0 configuration information, click "Authorize APIs".
- Click through the consent screen and then click "Exchange authorization code for tockens".
- Make note of your refresh token and access token.
- At the end of this process, you should have the following that will be used in future steps:
- A service account
- A client ID
- A client secret
- An access token
- A refresh token
- Create two storage buckets. One for input files and one for output files.
Please be sure to enable whatever services are required as you create the cloud function.
- Navigate to Cloud Functions and create a new function.
- Set the environment to 2nd gen.
- Enter a name for your function.
- Set the region to whatever you would like or use the default.
- Add a "Cloud Storage" trigger and set the bucket to the input bucket you created earlier.
- Change the service account to the service account you previously created.
- Expand the Runtime, build, connections and security settings area and enter the following settings:
- Set the memory allocated to whatever you would like, though I suggest 1 GiB.
- Set the timeout to 3600s (1 hour)
- Set the runtime service account to the service account you created earlier.
- Add the following runtime variables:
- Name: OUTPUT_BUCKET, value: The name of the output bucket you created earlier
- Name: CLIENT_ID, value: The client ID
- Name: CLIENT_SECRET, value: The client secret
- Name: ACCESS_TOKEN, value: The access token
- Name: REFRESH_TOKEN, value: The refresh token
- Name: TOKEN_URI, value: https://oauth2.googleapis.com/token
- Click next and set the runtime to 3.11.
- Set the entry point to "main" and copy the linker cloud function code into the editor.
- Copy the setting for requirements.txt into the editor.
- Deploy the function.
The input CSV file must follow this format.
The request type column accepts the following values:
- ads
- dv360
- dv360_link_proposal
The ads_customer_id values should not contain dashes.
The ads_personalization_enabled, dv360_campaign_data_sharing_enabled, and dv360_cost_data_sharing_enabled columns should only be set to true or false.