#' gtm_versions_live
#'
#' Get the live GTM container version
#' @param account_id The ID of the account
#' @param container_id The ID of the container
#' @param token An OAuth token object
#' @export
gtm_versions_live <- function(account_id,container_id,token) {
require(httr)
require(jsonlite)
require(tidyverse)
require(purrr)
token_status(token)
api_path <-'https://www.googleapis.com/tagmanager/v2'
parent <- paste('accounts',account_id,'containers',container_id,sep='/')
versions <- 'versions:live'
get_url <- paste(api_path,parent,versions,sep='/')
call <- easy_call('get',get_url,token)
call_content <- content(call,'parsed')
call_content <- compact(call_content)
#unwrap
variables <- gtm_df_vars(call_content)
builtin <- builtinvar_unwrap(call_content$builtInVariable)
triggers <- gtm_df_trigs(call_content)
container <- as_tibble(call_content$container) %>%
unnest(usageContext) %>%
tidycols() %>%
rename(container_name = name,
container_fingerprint = fingerprint,
container_url = tag_manager_url,
container_path = path)
tags <- gtm_list_tags(call_content)
call_content$trigger <- NULL
call_content$variable <- NULL
call_content$container <- NULL
call_content$tag <- NULL
call_content$builtInVariable <- NULL
metadata <- as_tibble(call_content) %>%
tidycols() %>%
left_join(container,by=c('account_id','container_id'))
big_list <- list()
big_list$metadata <- metadata
big_list$tags <- tags
big_list$triggers <- triggers
big_list$builtin_variables <- builtin
big_list$variables <- variables
return(big_list)
}
#' gtm_versions_get
#'
#' Get a specific GTM container version
#' @param account_id The ID of the account
#' @param container_id The ID of the container
#' @param version_id The ID of the version you want to get
#' @param token An OAuth token object
#' @export
gtm_versions_get <- function(account_id,container_id,version_id,token) {
require(httr)
require(jsonlite)
require(tidyverse)
token_status(token)
api_path <-'https://www.googleapis.com/tagmanager/v2'
path <- paste('accounts',account_id,'containers',container_id,'versions',version_id,sep='/')
get_url <- paste(api_path,path,sep='/')
call <- easy_call('get',get_url,token)
call_content <- content(call,'parsed')
#unwrap
variables <- gtm_df_vars(call_content)
builtin <- builtinvar_unwrap(call_content$builtInVariable)
triggers <- gtm_df_trigs(call_content)
container <- as_tibble(call_content$container) %>%
unnest(usageContext) %>%
tidycols()
tags <- gtm_list_tags(call_content)
call_content$trigger <- NULL
call_content$variable <- NULL
call_content$container <- NULL
call_content$tag <- NULL
call_content$builtInVariable <- NULL
metadata <- as_tibble(call_content) %>%
tidycols()
big_list <- list()
big_list$metadata <- metadata
big_list$tags <- tags
big_list$triggers <- triggers
big_list$builtin_variables <- builtin
big_list$variables <- variables
return(big_list)
}
#' gtm_versions_publish
#'
#' Publish a specific GTM container version
#' @param account_id The ID of the account
#' @param container_id The ID of the container
#' @param version_id The ID of the version you want to publish
#' @param token An OAuth token object
#' @export
gtm_versions_publish <- function(account_id,container_id,version_id,token) {
require(httr)
require(jsonlite)
require(tidyverse)
token_status(token)
api_path <-'https://www.googleapis.com/tagmanager/v2'
parent <- paste('accounts',account_id,'containers',container_id,'versions',version_id,sep='/')
pub <- 'publish'
pub_url <- paste(paste(api_path,parent,sep='/'),pub,sep = ':')
call <- easy_call('post',pub_url,token)
print(call$status_code)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.