The Management API v3 covers all API calls that are not data reporting related and are for getting meta information about your Google Analytics account or to change account settings.

Account structure

Shows the details for your account structure (Accounts > Web-properties > Views (profiles)) including creation time, user permissions etc.

The most day-to-day useful function is ga_account_list() which summarises all account web properties and views available to your user.

  • ga_account_list() - Get account summary including the ViewId
  • ga_accounts() - Get account metadata for your user
  • ga_webproperty() - Get web property
  • ga_webproperty_list() - List web properties for a particular accountId
  • ga_view() - Get single View (Profile)
  • ga_view_list() - List Views (Profile) for a particular accountId/webPropertyId

You can then also get the meta-data for that particular entity via ga_webproperty() or ga_view()

# ga_account_list is most commonly used
# (restricted to top 10 with the head() function)
head(ga_account_list(), n = 10)
## # A tibble: 10 x 11
##    accountId accountName internalWebProp… level websiteUrl type  starred
##    <chr>     <chr>       <chr>            <chr> <chr>      <chr> <lgl>  
##  1 79301104  cloudyr     118427305        STAN… http://cl… WEB   NA     
##  2 54516992  Demo Accou… 87479473         STAN… https://s… WEB   NA     
##  3 54516992  Demo Accou… 87479473         STAN… https://s… WEB   NA     
##  4 54516992  Demo Accou… 87479473         STAN… https://s… WEB   NA     
##  5 47480439  MarkEdmond… 78737968         STAN… http://ma… WEB   NA     
##  6 47480439  MarkEdmond… 78742336         STAN… http://ma… WEB   NA     
##  7 54019251  Sunholo We… 86845257         STAN… https://g… WEB   NA     
##  8 54019251  Sunholo We… 86845257         STAN… https://g… WEB   NA     
##  9 54019251  Sunholo We… 94325478         PREM… http://ma… WEB   NA     
## 10 54019251  Sunholo We… 94325478         PREM… http://ma… WEB   TRUE   
## # … with 4 more variables: webPropertyId <chr>, webPropertyName <chr>, viewId <chr>,
## #   viewName <chr>
# this only lists account meta-data
ga_accounts()
##         id             name             created             updated
## 1 47480439    MarkEdmondson 2014-01-25 12:17:05 2019-06-01 08:09:58
## 2 54019251 Sunholo Websites 2014-08-20 19:17:05 2019-07-31 18:51:55
## 3 54516992     Demo Account 2014-09-06 17:53:33 2019-06-10 17:56:03
## 4 79301104          cloudyr 2016-06-14 14:29:50 2016-06-14 14:29:50
##                            permissions.effective
## 1 COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
## 2 COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
## 3                               READ_AND_ANALYZE
## 4
# this gives meta-data for all web-properties for this accountId
ga_webproperty_list(47480439)
##              id accountId internalWebPropertyId                name
## 1 UA-47480439-1  47480439              78742336    markedmondson.me
## 2 UA-47480439-2  47480439              78737968 MarkEdmondson oldGA
##                websiteUrl    level profileCount    industryVertical dataRetentionTtl
## 1 http://markedmondson.me STANDARD            1 HOBBIES_AND_LEISURE        MONTHS_26
## 2 http://markedmondson.me STANDARD            1 HOBBIES_AND_LEISURE       INDEFINITE
##   dataRetentionResetOnNewActivity             created             updated
## 1                            TRUE 2014-01-25 12:17:05 2014-01-25 12:17:06
## 2                            TRUE 2014-01-25 12:19:20 2018-04-12 11:37:38
##   defaultProfileId                          permissions.effective
## 1             <NA> COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
## 2         81416156 COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
# this is meta-data for one particular web-property
ga_webproperty(accountId = 47480439, webPropertyId = "UA-47480439-1")
## $id
## [1] "UA-47480439-1"
## 
## $kind
## [1] "analytics#webproperty"
## 
## $selfLink
## [1] "https://www.googleapis.com/analytics/v3/management/accounts/47480439/webproperties/UA-47480439-1"
## 
## $accountId
## [1] "47480439"
## 
## $internalWebPropertyId
## [1] "78742336"
## 
## $name
## [1] "markedmondson.me"
## 
## $websiteUrl
## [1] "http://markedmondson.me"
## 
## $level
## [1] "STANDARD"
## 
## $profileCount
## [1] 1
## 
## $industryVertical
## [1] "HOBBIES_AND_LEISURE"
## 
## $dataRetentionTtl
## [1] "MONTHS_26"
## 
## $dataRetentionResetOnNewActivity
## [1] TRUE
## 
## $permissions
## $permissions$effective
## [1] "COLLABORATE"      "EDIT"             "MANAGE_USERS"     "READ_AND_ANALYZE"
## 
## 
## $created
## [1] "2014-01-25T12:17:05.492Z"
## 
## $updated
## [1] "2014-01-25T12:17:06.625Z"
## 
## $parentLink
## $parentLink$type
## [1] "analytics#account"
## 
## $parentLink$href
## [1] "https://www.googleapis.com/analytics/v3/management/accounts/47480439"
## 
## 
## $childLink
## $childLink$type
## [1] "analytics#profiles"
## 
## $childLink$href
## [1] "https://www.googleapis.com/analytics/v3/management/accounts/47480439/webproperties/UA-47480439-1/profiles"
# this is meta-data for the views under this accountId/webPropertyId
ga_view_list(accountId = 47480439, webPropertyId = "UA-47480439-1")
##         id accountId webPropertyId internalWebPropertyId              name currency
## 1 81416941  47480439 UA-47480439-1              78742336 All Web Site Data      USD
##            timezone              websiteUrl type             created
## 1 Europe/Copenhagen http://markedmondson.me  WEB 2014-01-25 12:17:05
##               updated eCommerceTracking
## 1 2015-06-14 13:18:53             FALSE
##                            permissions.effective
## 1 COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
# this is meta-data for this particular viewId (profileId)
ga_view(accountId = 47480439, webPropertyId = "UA-47480439-1", profileId = 81416941)
## $id
## [1] "81416941"
## 
## $kind
## [1] "analytics#profile"
## 
## $selfLink
## [1] "https://www.googleapis.com/analytics/v3/management/accounts/47480439/webproperties/UA-47480439-1/profiles/81416941"
## 
## $accountId
## [1] "47480439"
## 
## $webPropertyId
## [1] "UA-47480439-1"
## 
## $internalWebPropertyId
## [1] "78742336"
## 
## $name
## [1] "All Web Site Data"
## 
## $currency
## [1] "USD"
## 
## $timezone
## [1] "Europe/Copenhagen"
## 
## $websiteUrl
## [1] "http://markedmondson.me"
## 
## $type
## [1] "WEB"
## 
## $permissions
## $permissions$effective
## [1] "COLLABORATE"      "EDIT"             "MANAGE_USERS"     "READ_AND_ANALYZE"
## 
## 
## $created
## [1] "2014-01-25T12:17:05.492Z"
## 
## $updated
## [1] "2015-06-14T13:18:53.638Z"
## 
## $eCommerceTracking
## [1] FALSE
## 
## $parentLink
## $parentLink$type
## [1] "analytics#webproperty"
## 
## $parentLink$href
## [1] "https://www.googleapis.com/analytics/v3/management/accounts/47480439/webproperties/UA-47480439-1"
## 
## 
## $childLink
## $childLink$type
## [1] "analytics#goals"
## 
## $childLink$href
## [1] "https://www.googleapis.com/analytics/v3/management/accounts/47480439/webproperties/UA-47480439-1/profiles/81416941/goals"

Helper functions

These are helper utility functions to work with Google Analytics data.

  • ga_meta() - get a data.frame of available dimensions and metrics, or just use meta directly to get the version that comes with the library.
# you can just use `meta` as is to get the available metrics,
# here we just return the first 5 columns and rows for brevity
head(meta[,1:5])
##                      name      type dataType group     status
## 1             ga:userType DIMENSION   STRING  User     PUBLIC
## 2          ga:visitorType DIMENSION   STRING  User DEPRECATED
## 3         ga:sessionCount DIMENSION   STRING  User     PUBLIC
## 4           ga:visitCount DIMENSION   STRING  User DEPRECATED
## 5 ga:daysSinceLastSession DIMENSION   STRING  User     PUBLIC
## 6     ga:userDefinedValue DIMENSION   STRING  User     PUBLIC
# or ensure an up to date version by calling the metadata API.
head(ga_meta())[,1:5]
##                      name      type dataType group     status
## 1             ga:userType DIMENSION   STRING  User     PUBLIC
## 2          ga:visitorType DIMENSION   STRING  User DEPRECATED
## 3         ga:sessionCount DIMENSION   STRING  User     PUBLIC
## 4           ga:visitCount DIMENSION   STRING  User DEPRECATED
## 5 ga:daysSinceLastSession DIMENSION   STRING  User     PUBLIC
## 6     ga:userDefinedValue DIMENSION   STRING  User     PUBLIC
  • ga_aggregate - aggregate data down to the dimensions you specify, treating metrics correctly regarding if they should be averaged or summed. This is used internally when using anti-sampling, and is also useful to respond to dimension selections in Shiny dashboards, where you don’t want to perform a new API call each time you need aggregated data. Download all data first in a more unaggregated form, then use this function.
# use `aggregateGAData` so you can on the fly create summary data
ga_data <- google_analytics(81416156,
                            date_range = c("10daysAgo", "yesterday"),
                            metrics = c("sessions","bounceRate"), dimensions = c("hour","date"))
## [36mℹ[39m 2020-05-26 11:40:05 > Downloaded [ 240 ] rows from a total of [ 240 ].
head(ga_data)
##   hour       date sessions bounceRate
## 1   00 2020-05-16       10   60.00000
## 2   00 2020-05-17        8   37.50000
## 3   00 2020-05-18        9   44.44444
## 4   00 2020-05-19        8   50.00000
## 5   00 2020-05-20       11   63.63636
## 6   00 2020-05-21        8   50.00000
# if we want totals per hour over the dates:
ga_aggregate(ga_data[,c("hour","sessions")], agg_names = "hour")
## # A tibble: 24 x 2
##    hour  sessions
##    <chr>    <dbl>
##  1 00          92
##  2 01          64
##  3 02          58
##  4 03          64
##  5 04          70
##  6 05          74
##  7 06          59
##  8 07          66
##  9 08          82
## 10 09          89
## # … with 14 more rows
# it knows not to sum metrics that are rates:
ga_aggregate(ga_data[,c("hour","bounceRate")], agg_names = "hour")
## # A tibble: 24 x 2
##    hour  bounceRate
##    <chr>      <dbl>
##  1 00          53.4
##  2 01          65.1
##  3 02          69.3
##  4 03          60.5
##  5 04          65.4
##  6 05          79.9
##  7 06          78.8
##  8 07          66.1
##  9 08          75.4
## 10 09          66.3
## # … with 14 more rows
  • ga_allowed_metric_dim() - Create named list of allowed GA metrics/dimensions. This is useful to have nice looking labels for dimension and metric selection pickers, or to create lookup tables.
amd <- ga_allowed_metric_dim()
head(amd)
##                   Users               New Users          % New Sessions 
##              "ga:users"           "ga:newUsers" "ga:percentNewSessions" 
##      1 Day Active Users      7 Day Active Users     14 Day Active Users 
##          "ga:1dayUsers"          "ga:7dayUsers"         "ga:14dayUsers"

User management

  • ga_users_list() - list user access to your Google Analytics accounts, web properties or views
  • ga_users_delete() - delete user access via email
  • ga_users_delete_linkid() - delete user access via the linkId
  • ga_users_add() - add users to accounts
  • ga_users_update() - update a user

User management follows the recommended workflows outlined in this Google reference article.

The ga_users_* functions use the management APIs batching endpoint, to take advantage of the special increased quota limits when dealing with User management that API offers. For example, every 30 API calls that are batched that deal with user management only increments one API call against your management API quota. You can have 300 API calls in one batch (e.g. that costs 10 API calls against the quota), and googleAnalyticsR will split any list of emails into 300 emails per batch for you, so you can send in all emails you have.

By default, each Google Cloud Project gets 50 write requests per project per day, which if using batching means 1500 write/delete/update user operations per day.

You will need to use your own Google Cloud Platform project if using any write API operations seriously, otherwise you will be at the mercy of the shared googleAnalyticsR’s quota limits. See the section in the Setup page on how to setup using your own Google Project

To see which users are attached, use ga_users_list(). Each user email is referenced under the userRef.email column, whereas the unique IDs used to see which user is linked to where is the linkId which is unique to each user and link to your account, web property or view/profile.

Users can be attached at various levels in the hierarchy so you can call the function at various viewing angles.

# default will list all users that match the id you supply
ga_users_list(47480439)
ga_users_list(47480439, webPropertyId = "UA-47480439-2")
ga_users_list(47480439, webPropertyId = "UA-47480439-2", viewId = 81416156)

# only list users who have account level access
ga_users_list(47480439, webPropertyId = NULL, viewId = NULL)
# only list users who have webProperty and above access
ga_users_list(47480439, webPropertyId = "UA-47480439-2", viewId = NULL)

Users can be attached at account, web-property and view level.

Batching is incorporated for adding users, so you can pass in a vector of emails to add.

ga_users_add(c("the_email@company.com", "another_email@company.com"),
             permissions = "EDIT", accountId = 47480439)

To delete a user from all accounts, web-properties and views takes a few API calls to ga_users_list() to find all the possible links, which is done behind the scenes of ga_users_delete(). You can pass the function multiple emails to delete many at once, which is done via batching:

ga_users_list(47480439)

ga_users_delete("the_email@company.com", 47480439)

# delete many emails at once
ga_users_delete(c("the_email@company.com", "another_email@company.com"), accountId = 47480439)

For more fine grained control, the below examples shows a workflow to list and delete user access for one user at View level using the linkId.

# get the linkId for the user you want to delete
ga_users_list(47480439, webPropertyId = "UA-47480439-2", viewId = 81416156)
ga_users_delete_linkid("81416156:114834495587136933146", 47480439,
                webPropertyId = "UA-47480439-2", viewId = 81416156)

# check its gone
ga_users_list(47480439, webPropertyId = "UA-47480439-2", viewId = 81416156)

# can only delete at level user has access, the above deletion woud have failed if via:
ga_users_delete_linkid("47480439:114834495587136933146", 47480439)

You can also modify existing users via ga_users_update() - the below modifies on the web property level:

# the update to perform
o <- list(permissions = list(local = list("EDIT")))

ga_users_update("UA-123456-1:1111222233334444",
                update_object = o,
                accountId = 123456,
                webPropertyId = "UA-123456-1")

When using linkIds, make sure to use the correct linkId for the level of account, web-property or view you are operating on - the linkId starts with the accountId, UA code of web property, or ViewId number to distinguish between the various types.

Custom variables

Custom variable management for a Google Analytics property.

  • ga_custom_vars() - get meta data for a specific custom variable
  • ga_custom_vars_list() - list all custom dimensions or metrics
  • ga_custom_vars_create() - create a new custom variable
  • ga_custom_vars_patch() - update an existing custom variable

Using these you can scale setting up custom dimensions across your Google Analytics web properties. Custom dimension updates are governed by the same rules as when you create them in the web interface, as this Google article on custom dimensions and metrics explains.

You can’t delete custom dimensions, you can only de-activate them for reuse later on.

A workflow is shown below that creates, then updates a custom variable to a new name.

# create custom var
ga_custom_vars_create("my_custom_dim",
                      index = 15,
                      accountId = 54019251,
                      webPropertyId = "UA-54019251-4",
                      scope = "HIT",
                      active = FALSE)

# view custom dimension in list
ga_custom_vars_list(54019251, webPropertyId = "UA-54019251-4", type = "customDimensions")

# change a custom dimension
ga_custom_vars_patch("ga:dimension7",
                     accountId = 54019251,
                     webPropertyId = "UA-54019251-4",
                     name = "my_custom_dim2",
                     scope = "SESSION",
                     active = TRUE)

# view custom dimensions again to see change
ga_custom_vars_list(54019251, webPropertyId = "UA-54019251-4", type = "customDimensions")

AdWords

  • ga_adwords() Get Google Analytics - AdWords Link meta data
  • ga_adwords_list() List AdWords
  • ga_adwords_add_linkid() Create a link between and Adwords (Google ads) account and a Google Analytics property
  • ga_adwords_delete_linkid() Delete a Google Analytics webProperty-Google Ads link

For many websites Google search advertising, aka Adwords, is a key traffic channel which comes with its own reporting system. Linking Google Analytics with Adwords makes sense as it allows Google ads data to be included in Analytics reports and vice versa. For instance linking the two together can add to the Analytics reports more than 30 metrics and dimensions related to ads (such as the keywords that triggered an ad or the ad ROI) You can use the function ga_adwords_list() to request a list of existing links between Google Analytics and Adwords associated with your user. The ga_adwords() function provides meta data about a specific Google Analytics - Adwords link.

If a link between Analytics and Google ads has not been established, this can be done easily via the Management API using the ga_adwords_add_linkid() function. A requirement is that your email has access rights to both the Analytics and Adwords account. You will also need the Adwords customer ID which can be obtained via the Adwords API or UI. Also required is the id of the Google Analytics account and associated GA property to which the Adwords account will be linked. This operation will create a new entityAdWordsLinks resource. To remove this entityAdWordsLinks later if needed the ga_adwords_delete_linkid() function can be used.

# Lists webProperty-Google Ads links
ga_adwords_list(accountId = 65973592, webPropertyId = "UA-65973592-1")

# Get information about a web property-Google Ads link 
ga_adwords(accountId = 65973592, webPropertyId = "UA-65973592-1", webPropertyAdWordsLinkId = "QrcfI2DTSMayqbrLiHYUqw")

# establish a new link between GA and Adwords
ga_adwords_add_linkid(adwordsAccountId = "280-234-7592", linkName = "Google Ads Link", accountId = "65973592", webPropertyId = "UA-65973592-1")

#check that it has been added
ga_adwords_list(accountId = 65973592, webPropertyId = "UA-65973592-1")

# delete the link
ga_adwords_delete_linkid(accountId  = 65973592, webPropertyId ="UA-65973592-1", webPropertyAdWordsLinkId = "ezW2dyaiQcGheWRAo69nCw")

#check that the link has been removed
ga_adwords_list(accountId = 65973592, webPropertyId = "UA-65973592-1")

Custom Data Sources

See and upload custom data sources to Google Analytics

  • ga_custom_datasource() - List Custom Data Sources
  • ga_custom_upload() - Custom Data Source Upload Status
  • ga_custom_upload_file()- Upload a file to GA custom uploads
  • ga_custom_upload_list() - List the files in a GA custom upload

Experiments

  • ga_experiment() - Experiments Meta data
  • ga_experiment_list() - List Experiments

View Filters

The filter edit functions are contributed by @zselinger which allow you to update filters for your Google Analytics views at scale.

  • ga_filter() - Get specific filter for account
  • ga_filter_add() - Create a new filter and add it to the view (optional).
  • ga_filter_apply_to_view() - Apply an existing filter to view.
  • ga_filter_delete() - Delete a filter from account or remove from view.
  • ga_filter_list() - List filters for account
  • ga_filter_update() - Updates an existing filter.
  • ga_filter_update_filter_link() - Update an existing profile filter link. Patch semantics supported
  • ga_filter_view() - Get specific filter for view (profile)
  • ga_filter_view_list() - List filters for view (profile)

Goals

  • ga_goal() - Get goal
  • ga_goal_list() - List goals
  • ga_goal_add() - Create and add Goals to a web property
  • ga_goal_update() - Modify an existing goal

Example: Copying GA goals

We can programatically copy goal configurations from any GA view (the source) to another GA view (the destination) within an entirely separate property. This can be helpful to maintain standardised goal configurations for multiple properties, and also for GA migrations.

This example will first copy a single goal from one property to another, then use the map() function from purrr to copy multiple goals at once.

We use the Google Analytics demo account as the source view for this example - you can read more about the demo account here.

Auth and setup

We authenticate and load the necessary packages, following the instructions from the documentation.

library(tidyverse)
library(stringr)
library(rlist)
## Error in library(rlist): there is no package called 'rlist'

Copying a single goal

For this first section, we copy a single Goal from one view to another. To achieve this, we will:

  1. Retrieve the accountId, webPropertyId and viewId from our source GA view (the one where our goal to be copied over currently exists).
  2. Get a list of the goals currently configured in the source GA view.
  3. Retrieve the accountId, webPropertyId and viewId from our destination GA view (the one where our goal will be copied to).
  4. Get the configuration details of a single goal to be copied.
  5. Submit the goal details to our destination property.

1. Retrieve the accountId, webPropertyId and viewId from our source GA view

We use the ga_account_list() function, which returns an account summary for all available accounts as a dataframe. Then, we filter the dataframe down to a specific account and view name using the filter() and str_detect() functions from the tidyverse.

You can supply your own filter conditions as necessary, to locate your desired view information.

# Account info and list of goals for source, to be copied
source_account <- ga_account_list() %>%
  filter(str_detect(accountName, "Demo Account"), str_detect(viewName, "Master"))
source_account
## # A tibble: 1 x 11
##   accountId accountName internalWebProp… level websiteUrl type  starred webPropertyId
##   <chr>     <chr>       <chr>            <chr> <chr>      <chr> <lgl>   <chr>        
## 1 54516992  Demo Accou… 87479473         STAN… https://s… WEB   NA      UA-54516992-1
## # … with 3 more variables: webPropertyName <chr>, viewId <chr>, viewName <chr>

2. Get a list of the goals currently configured from our source GA view

Now that we have the account summary, we can use the view details to get a list of goal data, with each item in the list showing goal details.

source_goals <- ga_goal_list(source_account$accountId, source_account$webPropertyId, source_account$viewId)
source_goals
##   id accountId webPropertyId internalWebPropertyId profileId               name
## 1  1  54516992 UA-54516992-1              87479473  92320289 Purchase Completed
## 2  2  54516992 UA-54516992-1              87479473  92320289      Engaged Users
## 3  3  54516992 UA-54516992-1              87479473  92320289      Registrations
## 4  4  54516992 UA-54516992-1              87479473  92320289   Entered Checkout
##   value active            type             created             updated
## 1     0   TRUE URL_DESTINATION 2014-10-10 20:13:47 2016-11-10 23:07:35
## 2     0   TRUE VISIT_NUM_PAGES 2015-02-23 16:18:06 2015-04-14 12:02:21
## 3     0   TRUE URL_DESTINATION 2015-02-27 12:15:01 2016-07-26 16:14:09
## 4     0   TRUE URL_DESTINATION 2015-07-20 23:57:22 2016-07-26 16:19:40
##                                 urlDestinationDetails.url
## 1                                  /ordercompleted\\.html
## 2                                                    <NA>
## 3                                 /registersuccess\\.html
## 4 /yourinfo\\.html|/guestregister\\.html|/shipping\\.html
##   urlDestinationDetails.caseSensitive urlDestinationDetails.matchType
## 1                               FALSE                           REGEX
## 2                                  NA                            <NA>
## 3                               FALSE                           REGEX
## 4                               FALSE                           REGEX
##   urlDestinationDetails.firstStepRequired
## 1                                    TRUE
## 2                                      NA
## 3                                   FALSE
## 4                                   FALSE
##                                                                                                                            urlDestinationDetails.steps
## 1 1:4,c("Cart", "Billing and Shipping", "Payment", "Review"),c("/basket\\\\.html", "/yourinfo\\\\.html", "/payment\\\\.html", "/revieworder\\\\.html")
## 2                                                                                                                                                     
## 3                                                                                                                                                     
## 4                                                                                                                                                     
##   visitNumPagesDetails.comparisonType visitNumPagesDetails.comparisonValue
## 1                                <NA>                                 <NA>
## 2                        GREATER_THAN                                   10
## 3                                <NA>                                 <NA>
## 4                                <NA>                                 <NA>

3. Retrieve the accountId, webPropertyId and viewId from our destination GA view

We again filter the results from ga_account_list(), to get account information for our destination GA property. In this example, we filter for “Your_Account” and the view called “Filtered”.

The dest_account dataframe should contain the same columns and data types as your source_account dataframe.

# Account info for destination account
dest_account <- ga_account_list() %>%
  filter(str_detect(accountName, "Your_Account"), str_detect(viewName, "Filtered"))

4. Get the configuration details of a single goal to be copied.

For this first example, we add a single goal (ID 1) to the destination view, passed as a list to the ga_goal_add() function.

We now use the ga_goal() function to retrieve the goal specifications as a list. We use ga_goal() because it provides the goal configuration data in the necessary format for our goal_add() request.

In the example below, we retrieve the details for the goal in slot 1.

# Get goal ID 1
goal_one <- ga_goal(source_account$accountId, source_account$webPropertyId, source_account$viewId,
                    goalId = 1) %>%
  # Strip out instance-specific metadata (property, profile, view data and original creation dates)
  list.remove( c("accountId", "webPropertyId", "selfLink", "internalWebPropertyId", "profileId", "parentLink", "created", "updated"))
## Error in list.remove(., c("accountId", "webPropertyId", "selfLink", "internalWebPropertyId", : could not find function "list.remove"
goal_one
## Error in eval(expr, envir, enclos): object 'goal_one' not found

5. Submit the goal details to our destination property.

We can then use the goal details contained in goal_one to submit a ga_goal_add() request to our destination property.

ga_goal_add(goal_one, dest_account$accountId, dest_account$webPropertyId, dest_account$viewId)

All being well, you should see console output containing the details of your newly submitted goal in the destination property.

You can repeat the above steps for any goal IDs you’d like to copy over, and to one or multiple destination views.


Copying multiple goals

Using the map() function from the tidyverse, we can quickly scale up this approach. We can copy all goals from a view at once, rather than one at a time.

First, we define a function to copy a single goal, given a goal ID, details of the source view ID and destination view IDs. In effect, we make a function to perform steps 1-5 from the “Copying a single goal” section in this page.

# Takes a goal ID, source account information & dest account information, copies goal over
copy_goal <- function(goal_id, source_df, dest_df) {
  source_goal <- ga_goal(source_df$accountId, source_df$webPropertyId, source_df$viewId, goal_id) %>%
    list.remove( c("accountId", "webPropertyId", "selfLink", "internalWebPropertyId", "profileId", "parentLink", "created", "updated"))
  ga_goal_add(source_goal, dest_df$accountId, dest_df$webPropertyId, dest_df$viewId)
}

Having our goal-copying function defined, it is a simple step to apply it across all goal IDs from the source view.

The example below re-uses the source_goals, source_account and dest_account objects which were created earlier.

# For each goal ID in our source view, apply the copy_goal function, 
# using source_account and dest_account account parameters as fixed 2nd / third arguments
map(source_goals$id, copy_goal, source_account, dest_account)

Write request limits

At the time of writing, there is a daily limit of 50 write requests per day, per Google Cloud project, which restricts the number of times this can be performed. However, it is possible to request that this limit be increased.

For more information, check the Google documentation at https://developers.google.com/analytics/devguides/config/mgmt/v3/limits-quotas#write_requests.

Remarketing segments

Remarketing segments lets you target users in Google Ads from Google Analytics segments.

  • ga_remarketing_estimate() - Estimate number of users added to the segment yesterday
  • ga_remarketing_get() - Get a remarketing audience
  • ga_remarketing_list() - List remarketing audiences
  • ga_remarketing_build() - Create definitions to be used within ga_remarketing_create()
  • ga_remarketing_create() - Create a remarketing audience

A demo of how you could use this based on your existing GA segments is:

adword_list <- ga_adwords_list(123456, "UA-123456-1")

adword_link <- ga_adword(adword_list$id[[1]])

segment_list <- ga_segment_list()$items$definition

my_remarketing1 <- ga_remarketing_build(segment_list[[1]],
                      state_duration = "TEMPORARY",
                      membershipDurationDays = 90,
                      daysToLookBack = 14)
my_remarketing2 <- ga_remarketing_build(segment_list[[2]],
                      state_duration = "PERMANENT",
                      membershipDurationDays = 7,
                      daysToLookBack = 31)

# state based only can include exclusions
ga_remarketing_create(adwords_link = adword_link,
                     include = my_remarketing1, exclude = my_remarketing2,
                     audienceType = "STATE_BASED", name = "my_remarketing_seg1")

Unsampled reports

Available only for GA360 accounts, you will need to authenticate with the Google drive scope to get download access. The download functions are contributed by @j450h1

  • ga_unsampled() - Get Unsampled Report Meta Data
  • ga_unsampled_download() - Download Unsampled Report from Google Drive
  • ga_unsampled_list() - List Unsampled Reports

Users

  • ga_clientid_hash() - Creates the clientID hash that is used in BigQuery GA360 exports
  • ga_clientid_deletion() - Delete a website visitor from Google Analytics