Created
September 13, 2016 14:33
-
-
Save IronistM/1d95b2bee454fcff4fe643a2dc979ec8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Build the package ------------- | |
## Now, build the `googletagmanagerv1.auto` package | |
# devtools::install_local("C:/Users/Manos/dev/R/autoGoogleAPI/googletagmanagerv1.auto") | |
# Package: googletagmanagerv1.auto | |
# Title: Tag Manager API | |
# Version: 0.0.0.9000 | |
# Authors@R: c(person("Mark", "Edmondson",email = "[email protected]", | |
# role = c("aut", "cre"))) | |
# Description: Accesses Tag Manager accounts and containers. Auto-generated via | |
# googleAuthR. | |
# Depends: R (>= 3.3.1) | |
# License: MIT + file LICENSE | |
# Encoding: UTF-8 | |
# LazyData: true | |
# Imports: googleAuthR (>= 0.3) | |
# RoxygenNote: 5.0.1 | |
# Author: Mark Edmondson [aut, cre] | |
# Maintainer: Mark Edmondson <[email protected]> | |
# Built: R 3.3.1; ; 2016-09-13 10:48:03 UTC; windows | |
# RemoteType: local | |
# RemoteUrl: C:/Users/Manos/dev/R/autoGoogleAPI/googletagmanagerv1.auto | |
# RemoteSha: 0.0.0.9000 | |
library(googleAuthR); | |
library(googletagmanagerv1.auto) | |
## Set the desired scopes for our problem(s) | |
options(googleAuthR.scopes.selected = c('https://www.googleapis.com/auth/tagmanager.delete.containers', | |
'https://www.googleapis.com/auth/tagmanager.edit.containers', | |
'https://www.googleapis.com/auth/tagmanager.edit.containerversions', | |
'https://www.googleapis.com/auth/tagmanager.manage.accounts', | |
'https://www.googleapis.com/auth/tagmanager.manage.users', | |
'https://www.googleapis.com/auth/tagmanager.publish', | |
'https://www.googleapis.com/auth/tagmanager.readonly')) | |
## Now authenticate to Google | |
gar_auth() | |
## Get the accounts programmatically | |
accounts.gtm <- accounts.list() | |
## Sample Ids | |
accountId <- 65691 | |
containerId <- 71466 | |
## Define functions for the `googletagmanagerv1` package | |
## but let's use them directly here | |
tags.list <- function(accountId,containerId) { | |
url <- paste0("https://www.googleapis.com/tagmanager/v1/accounts/",accountId,"/containers/",containerId,"/tags") | |
# tagmanager.tags.list | |
f <- gar_api_generator(url, "GET", data_parse_function = function(x) x) | |
f() | |
} | |
triggers.list <- function(accountId,containerId) { | |
url <- paste0("https://www.googleapis.com/tagmanager/v1/accounts/",accountId,"/containers/",containerId,"/triggers") | |
# tagmanager.triggers.list | |
f <- gar_api_generator(url, "GET", data_parse_function = function(x) x) | |
f() | |
} | |
variables.list <- function(accountId,containerId) { | |
url <- paste0("https://www.googleapis.com/tagmanager/v1/accounts/",accountId,"/containers/",containerId,"/variables") | |
# tagmanager.variables.list | |
f <- gar_api_generator(url, "GET", data_parse_function = function(x) x) | |
f() | |
} | |
container.tags <- containers.list(65691,71466) | |
container.triggers <- triggers.list(65691,71466) | |
container.variables <- variables.list(65691,71466) | |
## Parameter is a `JSON` (so in `R` this is a `list`), that we will not use for now | |
# str(container.tags$tags$parameter) | |
## Objects of interest | |
tags <- container.tags$tags | |
triggers <- container.triggers$triggers | |
variables <- container.variables$variables | |
## Push it to a Google Sheet | |
require(googlesheets) | |
## Auth with `googlesheets` | |
gs_auth() | |
## Register a new Google Sheet to pass the data | |
# gs_new("(Auto) GTM Implementation", verbose = TRUE) | |
s_id <- gs_title("(Auto) GTM Implementation", verbose = TRUE) | |
# gs_ws_new(ss=s_id, ws_title = "Tags") | |
# gs_ws_new(ss=s_id, ws_title = "Triggers") | |
# gs_ws_new(ss=s_id, ws_title = "Variables") | |
yo.tags <- gs_ws_new(ss=s_id, ws_title="Tags" , input = tags, trim = TRUE) | |
yo.triggers <- gs_ws_new(ss=s_id, ws_title="Triggers", input = triggers, trim = TRUE) | |
yo.variables <- gs_ws_new(ss=s_id, ws_title="Variables", input = variables, trim = TRUE) | |
## Share the spreadsheet | |
s_id$browser_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment