Я нашел сообщение "(Авто) Документировать вашу реализацию Google Tag Manager" (https://statsravingmad.com/measure/document-your-gtm-implementation/).
)
Если я не ошибаюсь, я должен запустить этот скрипт на RStudio, чтобы получить spreadSHEET со всем контентом из моего GTM, верно?
Итак, когда я запускаю приведенный ниже код в RStudio, он показывает мне:
«Ошибка в accountId: объект« accountId »не найден»
Важно сказать, что эти данные (accountId <- 3097258993 & containerId <- 8968207) я создал для фиктивных тестов. </p>
Кто-нибудь знает, что я могу сделать, чтобы решить эту проблему?
Спасибо!
library(googleAuthR);
library(googlesheets) ## In order to push it to a Google Sheet
## 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(new_user = T)
## Auth with `googlesheets` as well (since this can be a different account)
gs_auth()
## Define functions for the `googletagmanagerv1` package
## but let's use them directly here
accounts.list <- function() {
url <- "https://www.googleapis.com/tagmanager/v1/accounts"
# tagmanager.accounts.list
f <- gar_api_generator(url, "GET", data_parse_function = function(x) x)
f()
}
containers.list <- function(accountId) {
url <- paste0("https://www.googleapis.com/tagmanager/v1/accounts/",accountId,"/containers/")
# tagmanager.tags.list
f <- gar_api_generator(url, "GET", data_parse_function = function(x) x)
f()
}
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()
}
## We can get the accounts using the `accounts.list()`
## Sample Ids (originating from this blog)
accountId <- 3097258993
containerId <- 8968207
time <- 3;
## A loop for generic use
for (acc_Id in accountId){
for (con_Id in containerId) {
container.tags <- tags.list(acc_Id,con_Id)
container.triggers <- triggers.list(acc_Id,con_Id)
container.variables <- variables.list(acc_Id,con_Id)
## 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
## Register a new Google Sheet to pass the data
gs_new(paste("(Auto) GTM Implementation - ",acc_Id,"_",con_Id), verbose = TRUE)
s_id <- gs_title(paste("(Auto) GTM Implementation - ",acc_Id,"_", con_Id), verbose = TRUE)
yo.tags <- gs_ws_new(ss=s_id, ws_title="Tags" , input = tags[,1:10], 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)
## Get Google Sheet URL
# s_id$browser_url
# > https://docs.google.com/spreadsheets/d/1qibV3BSOtzSlI0vG6JC8xnzqnu6TnpFuxabaYN2vXeI/
}
## This is used to cool off the Google Drive API calls...
## Since we only write to one Google Sheet we don't need it in this run.
# Sys.sleep(time)
}