gtm_variables_create: Create a new variable

View source: R/variables.R

gtm_variables_createR Documentation

Create a new variable

Description

This takes a variable resource and creates a new variable in GTM.

Usage

gtm_variables_create(account_id, container_id, workspace_id, variable_object)

Arguments

account_id

Account Id

container_id

Container Id

workspace_id

Workspace Id

variable_object

Variable Object

See Also

https://developers.google.com/tag-platform/tag-manager/api/v2/reference/accounts/containers/workspaces/variables/create

https://developers.google.com/tag-platform/tag-manager/api/v2/reference/accounts/containers/workspaces/variables#resource-representations

Other variable functions: gtm_variables_delete(), gtm_variables_get(), gtm_variables_list(), gtm_variables_revert(), gtm_variables_update()

Examples


## Not run: 
accountId <- 1234567
containerId <- 7654321
workspaceId <- 3

variable <- list(
  name = 'Custom JS Variable',
  type = 'jsm',
  parameter = list(
    list(
      type = 'template',
      key = 'javascript',
      value = 'function(){\n  return document.querySelector(\"form\").id;\n}'
    )
  )
)

cjsVariable <- gtm_variables_create(accountId, containerId, workspaceId, variable)

variable2 <- list(
name = 'Lookup Table',
type = 'smm',
parameter = list(
  list(
        type = 'boolean',
        key = 'setDefaultValue',
        value = 'false'
    ),
    list(
        type = 'template',
        key = 'input',
        value = '{{Page Hostname}}'
    ),
    list(
        type = 'list',
        key = 'map',
        list = list(
            list(
            type = 'map',
            map = list(list(
                type = 'template',
                key = 'key',
                value = 'google.co.uk'
            ),
            list(
                type = 'template',
                key = 'value',
                value = 'UA-123456-1'
            )
       )
    ),
    list(
            type = 'map',
            map = list(list(
                type = 'template',
                key = 'key',
                value = 'bing.com'
            ),
            list(
                type = 'template',
                key = 'value',
                value = 'UA-123456-2'
            )
       )
    )
    )
   )
  )
 )

lookupTable <- gtm_variables_create(accountId, containerId, workspaceId, variable2)


## End(Not run)


googleTagManageR documentation built on April 17, 2022, 1:05 a.m.