R/gtm_builtin_variables_methods.R

Defines functions gtm_builtin_variables_delete gtm_builtin_variables_create gtm_builtin_variables_list

Documented in gtm_builtin_variables_create gtm_builtin_variables_delete gtm_builtin_variables_list

#' gtm_builtin_variables_list
#'
#' Lists all the enabled Built-In Variables of a GTM Container.
#' @param account_id The ID of the account
#' @param container_id The ID of the container
#' @param workspace_id The ID of the workspace. Defaults to NULL because this will default to the default workspace.
#' @param token An OAuth token object
#' @param verbose If you want a message letting you know that your results have been successfully retrieved. Defaults to FALSE
#' @export

gtm_builtin_variables_list <- function(account_id,container_id,token,workspace_id=NULL,verbose = FALSE) {

  require(neugelbtools)
  require(httr)
  require(tidyverse)
  require(purrr)

  "
  NOTE: The documentation suggests that you can use a pageToken to paginate your requests, but it doesn't provide any more detail about how it works.
  So I have left it out!
  "
token_status(token)

  path <- paste('https://www.googleapis.com/tagmanager/v2/accounts',account_id,'containers',container_id,'workspaces',sep='/')

  wid <- wspace_picker(account_id,container_id,workspace_id,token)

  api_url <- paste(path,wid,'built_in_variables',sep='/')

  call <- easy_call('get',api_url,token)

  call_content <- content(call,'parsed')

  bivars <- builtinvar_unwrap(call_content$builtInVariable)

  verbose_calls(call,call_content,verbose)

  return(bivars)

}

#' gtm_builtin_variables_create
#'
#' Create a Built-In Variable in a GTM Container.
#' @param account_id The ID of the account
#' @param container_id The ID of the container
#' @param workspace_id The ID of the workspace.
#' @param variable The variable name, see full list at https://developers.google.com/tag-manager/api/v2/reference/accounts/containers/workspaces/built_in_variables/list
#' @param token An OAuth token object
#' @param verbose If you want a message letting you know that your results have been successfully retrieved. Defaults to FALSE
#' @export

gtm_builtin_variables_create <- function(account_id,container_id,workspace_id,variable,token,verbose=FALSE) {

    token_status(token)

    update_val <- paste("?type=",variable,sep='')

    post_url <- paste('https://www.googleapis.com/tagmanager/v2/accounts',account_id,'containers',container_id,'workspaces',workspace_id,'built_in_variables',update_val,sep='/')

    call <- easy_call('post',post_url,token)

    call_content <- content(call,'parsed')

    verbose_calls(call,call_content,verbose)

}

#' gtm_builtin_variables_delete
#'
#' Delete a Built-In Variable in a GTM Container.
#' @param account_id The ID of the account
#' @param container_id The ID of the container
#' @param workspace_id The ID of the workspace.
#' @param variable The variable name, see full list at https://developers.google.com/tag-manager/api/v2/reference/accounts/containers/workspaces/built_in_variables/list
#' @param token An OAuth token object
#' @param verbose If you want a message letting you know that your results have been successfully retrieved. Defaults to FALSE
#' @export

gtm_builtin_variables_delete <- function(account_id,container_id,workspace_id,variable,token,verbose=FALSE) {

    token_status(token)

    update_val <- paste("?type=",variable,sep='')

    delete_url <- paste('https://www.googleapis.com/tagmanager/v2/accounts',account_id,'containers',container_id,'workspaces',workspace_id,'built_in_variables',update_val,sep='/')

    call <- easy_call('delete',delete_url,token)

    call_content <- content(call,'parsed')

    verbose_calls(call,call_content,verbose)

}
neugelb/gtmr documentation built on June 25, 2020, 10:06 a.m.