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.

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)
##    accountId      accountName internalWebPropertyId    level
## 1   79301104          cloudyr             118427305 STANDARD
## 2   54516992     Demo Account              87479473 STANDARD
## 3   54516992     Demo Account              87479473 STANDARD
## 4   54516992     Demo Account              87479473 STANDARD
## 5   73050356     GDE Tracking             110873793 STANDARD
## 6   73050356     GDE Tracking             110873793 STANDARD
## 7   47480439    MarkEdmondson              78737968 STANDARD
## 8   47480439    MarkEdmondson              78742336 STANDARD
## 9   47584925   RaspberryPi UA              78875592 STANDARD
## 10  54019251 Sunholo Websites              86845257 STANDARD
##                                 websiteUrl webPropertyId
## 1                 http://cloudyr.github.io UA-79301104-1
## 2  https://shop.googlemerchandisestore.com UA-54516992-1
## 3  https://shop.googlemerchandisestore.com UA-54516992-1
## 4  https://shop.googlemerchandisestore.com UA-54516992-1
## 5                  http://gde-websites.com UA-73050356-1
## 6                  http://gde-websites.com UA-73050356-1
## 7                  http://markedmondson.me UA-47480439-2
## 8                  http://markedmondson.me UA-47480439-1
## 9                           http://erm.com UA-47584925-1
## 10        https://gwt-download.appspot.com UA-54019251-1
##             webPropertyName type starred    viewId          viewName
## 1       the cloudyr project  WEB      NA 123875646 All Web Site Data
## 2  Google Merchandise Store  WEB      NA  92320289     1 Master View
## 3  Google Merchandise Store  WEB      NA  92324711       2 Test View
## 4  Google Merchandise Store  WEB      NA  90822334   3 Raw Data View
## 5              GDE Tracking  WEB      NA 115760903      Bot excluded
## 6              GDE Tracking  WEB      NA 115751114          RAW DATA
## 7       MarkEdmondson oldGA  WEB    TRUE  81416156         Live Blog
## 8          markedmondson.me  WEB      NA  81416941 All Web Site Data
## 9               raspberryPi  WEB      NA  81569059 All Web Site Data
## 10             GWT Download  WEB      NA  90130533 All Web Site Data
# this only lists account meta-data
ga_accounts()
##         id             name             created             updated
## 1 47480439    MarkEdmondson 2014-01-25 12:17:05 2015-08-10 18:47:15
## 2 47584925   RaspberryPi UA 2014-01-29 17:01:47 2015-08-10 21:40:04
## 3 54019251 Sunholo Websites 2014-08-20 19:17:05 2015-08-10 19:50:44
## 4 54516992     Demo Account 2014-09-06 17:53:33 2018-02-11 23:40:54
## 5 73050356     GDE Tracking 2016-01-29 20:40:44 2016-01-29 20:40:44
## 6 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 COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
## 4                               READ_AND_ANALYZE
## 5 COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
## 6
# 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
## 1 http://markedmondson.me STANDARD            1 HOBBIES_AND_LEISURE
## 2 http://markedmondson.me STANDARD            1 HOBBIES_AND_LEISURE
##   dataRetentionTtl dataRetentionResetOnNewActivity             created
## 1        MONTHS_26                            TRUE 2014-01-25 12:17:05
## 2       INDEFINITE                            TRUE 2014-01-25 12:19:20
##               updated defaultProfileId
## 1 2014-01-25 12:17:06             <NA>
## 2 2018-04-12 11:37:38         81416156
##                            permissions.effective
## 1 COLLABORATE,EDIT,MANAGE_USERS,READ_AND_ANALYZE
## 2 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"    
## [4] "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
## 1 81416941  47480439 UA-47480439-1              78742336 All Web Site Data
##   currency          timezone              websiteUrl type
## 1      USD Europe/Copenhagen http://markedmondson.me  WEB
##               created             updated eCommerceTracking
## 1 2014-01-25 12:17:05 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"    
## [4] "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.

# you can just use `meta` as is to get the available metrics, or ensure an up to date version by calling the metadata API.
# 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
head(google_analytics_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
# 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"))
## 2018-12-16 22:34:48> Downloaded [240] rows from a total of [240].
head(ga_data)
##   hour       date sessions bounceRate
## 1   00 2018-12-06        9   88.88889
## 2   00 2018-12-07        5   60.00000
## 3   00 2018-12-08       18   88.88889
## 4   00 2018-12-09        6   66.66667
## 5   00 2018-12-10        5   60.00000
## 6   00 2018-12-11       18   33.33333
# if we want totals per hour over the dates:
aggregateGAData(ga_data[,c("hour","sessions")], agg_names = "hour")
## # A tibble: 24 x 2
##    hour  sessions
##    <chr>    <dbl>
##  1 00         109
##  2 01          67
##  3 02          66
##  4 03          54
##  5 04          63
##  6 05          51
##  7 06          72
##  8 07          62
##  9 08          92
## 10 09         131
## # ... with 14 more rows
# it knows not to sum metrics that are rates:
aggregateGAData(ga_data[,c("hour","bounceRate")], agg_names = "hour")
## # A tibble: 24 x 2
##    hour  bounceRate
##    <chr>      <dbl>
##  1 00          69.9
##  2 01          76.1
##  3 02          73.1
##  4 03          79.8
##  5 04          74.5
##  6 05          84.2
##  7 06          76.6
##  8 07          87.9
##  9 08          70.9
## 10 09          66.2
## # ... with 14 more rows
#
amd <- 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

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

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

library(googleAnalyticsR)
ga_auth()

ga_users_list(47480439)
ga_users_list(47480439, webPropertyId = "UA-47480439-2")
ga_users_list(47480439, webPropertyId = "UA-47480439-2", viewId = 81416156)

To delete a user from all accounts, web-properties and views takes a few API calls to find all the possible links, this is done behind the scenes of ga_users_delete():


ga_users_list(47480439)

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

User management benefits from increased quota limits if you batch requests, at the rate of 30 calls for 1 hit. This 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)

The below examples shows a workflow to list and delete user access for one user at View level if you wish to do it via fine-grained control in the linkId.

library(googleAnalyticsR)
ga_auth()

# get the linkId for the user you want to delete
ga_users_list(47480439, webPropertyId = "UA-47480439-2", viewId = 81416156)
ga_users_delete("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("47480439:114834495587136933146", 47480439)

You can also modify existing users via ga_users_update()

# 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")

AdWords

Custom Data Sources

See and upload custom data sources to Google Analytics

Custom variables

Custom variables for a Google Analytics property.

Experiments

View Filters

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

Goals

Remarketing segments

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

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

Users