Requires authorization
Creates a GTM trigger. Try it now or see an example.
Request
HTTP request
POST https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers/containerId/triggers
Parameters
Parameter name | Value | Description |
---|---|---|
Path parameters | ||
accountId |
string |
The GTM Account ID. |
containerId |
string |
The GTM Container ID. |
Authorization
This request requires authorization with the following scope (read more about authentication and authorization).
Scope |
---|
https://www.googleapis.com/auth/tagmanager.edit.containers |
Request body
In the request body, supply a Triggers resource with the following properties:
Property name | Value | Description | Notes |
---|---|---|---|
Required Properties | |||
autoEventFilter[].parameter[] |
list |
A list of named parameters (key/value), depending on the condition's type. Notes:
|
writable |
autoEventFilter[].parameter[].type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
autoEventFilter[].type |
string |
The type of operator for this condition.
Acceptable values are:
|
writable |
checkValidation.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
continuousTimeMinMilliseconds.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
customEventFilter[].parameter[] |
list |
A list of named parameters (key/value), depending on the condition's type. Notes:
|
writable |
customEventFilter[].parameter[].type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
customEventFilter[].type |
string |
The type of operator for this condition.
Acceptable values are:
|
writable |
eventName.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
filter[].parameter[] |
list |
A list of named parameters (key/value), depending on the condition's type. Notes:
|
writable |
filter[].parameter[].type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
filter[].type |
string |
The type of operator for this condition.
Acceptable values are:
|
writable |
horizontalScrollPercentageList.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
interval.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
intervalSeconds.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
limit.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
maxTimerLengthSeconds.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
name |
string |
Trigger display name. | writable |
parameter[].type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
selector.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
totalTimeMinMilliseconds.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
type |
string |
Defines the data layer event that causes this trigger.
Acceptable values are:
|
writable |
uniqueTriggerId.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
verticalScrollPercentageList.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
visibilitySelector.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
visiblePercentageMax.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
visiblePercentageMin.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
waitForTags.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
waitForTagsTimeout.type |
string |
The parameter type. Valid values are:
Acceptable values are:
|
writable |
Optional Properties | |||
autoEventFilter[] |
list |
Used in the case of auto event tracking. | writable |
autoEventFilter[].parameter[].key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
autoEventFilter[].parameter[].list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
autoEventFilter[].parameter[].map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
autoEventFilter[].parameter[].value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
checkValidation |
nested object |
Whether or not we should only fire tags if the form submit or link click event is not cancelled by some other event handler (e.g. because of validation). Only valid for Form Submission and Link Click triggers. | writable |
checkValidation.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
checkValidation.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
checkValidation.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
checkValidation.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
continuousTimeMinMilliseconds |
nested object |
A visibility trigger minimum continuous visible time (in milliseconds). Only valid for AMP Visibility trigger. | writable |
continuousTimeMinMilliseconds.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
continuousTimeMinMilliseconds.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
continuousTimeMinMilliseconds.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
continuousTimeMinMilliseconds.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
customEventFilter[] |
list |
Used in the case of custom event, which is fired iff all Conditions are true. | writable |
customEventFilter[].parameter[].key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
customEventFilter[].parameter[].list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
customEventFilter[].parameter[].map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
customEventFilter[].parameter[].value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
eventName |
nested object |
Name of the GTM event that is fired. Only valid for Timer triggers. | writable |
eventName.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
eventName.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
eventName.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
eventName.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
filter[] |
list |
The trigger will only fire iff all Conditions are true. | writable |
filter[].parameter[].key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
filter[].parameter[].list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
filter[].parameter[].map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
filter[].parameter[].value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
horizontalScrollPercentageList |
nested object |
List of integer percentage values for scroll triggers. The trigger will fire when each percentage is reached when the view is scrolled horizontally. Only valid for AMP scroll triggers. | writable |
horizontalScrollPercentageList.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
horizontalScrollPercentageList.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
horizontalScrollPercentageList.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
horizontalScrollPercentageList.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
interval |
nested object |
Time between triggering recurring Timer Events (in milliseconds). Only valid for Timer triggers. | writable |
interval.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
interval.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
interval.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
interval.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
intervalSeconds |
nested object |
Time between Timer Events to fire (in seconds). Only valid for AMP Timer trigger. | writable |
intervalSeconds.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
intervalSeconds.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
intervalSeconds.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
intervalSeconds.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
limit |
nested object |
Limit of the number of GTM events this Timer Trigger will fire. If no limit is set, we will continue to fire GTM events until the user leaves the page. Only valid for Timer triggers. | writable |
limit.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
limit.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
limit.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
limit.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
maxTimerLengthSeconds |
nested object |
Max time to fire Timer Events (in seconds). Only valid for AMP Timer trigger. | writable |
maxTimerLengthSeconds.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
maxTimerLengthSeconds.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
maxTimerLengthSeconds.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
maxTimerLengthSeconds.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
parameter[].key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
parameter[].list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
parameter[].map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
parameter[].value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
selector |
nested object |
A click trigger CSS selector (i.e. "a", "button" etc.). Only valid for AMP Click trigger. | writable |
selector.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
selector.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
selector.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
selector.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
totalTimeMinMilliseconds |
nested object |
A visibility trigger minimum total visible time (in milliseconds). Only valid for AMP Visibility trigger. | writable |
totalTimeMinMilliseconds.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
totalTimeMinMilliseconds.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
totalTimeMinMilliseconds.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
totalTimeMinMilliseconds.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
uniqueTriggerId |
nested object |
Globally unique id of the trigger that auto-generates this (a Form Submit, Link Click or Timer listener) if any. Used to make incompatible auto-events work together with trigger filtering based on trigger ids. This value is populated during output generation since the tags implied by triggers don't exist until then. Only valid for Form Submit, Link Click and Timer triggers. | writable |
uniqueTriggerId.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
uniqueTriggerId.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
uniqueTriggerId.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
uniqueTriggerId.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
verticalScrollPercentageList |
nested object |
List of integer percentage values for scroll triggers. The trigger will fire when each percentage is reached when the view is scrolled vertically. Only valid for AMP scroll triggers. | writable |
verticalScrollPercentageList.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
verticalScrollPercentageList.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
verticalScrollPercentageList.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
verticalScrollPercentageList.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
visibilitySelector |
nested object |
A visibility trigger CSS selector (i.e. "#id"). Only valid for AMP Visibility trigger. | writable |
visibilitySelector.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
visibilitySelector.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
visibilitySelector.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
visibilitySelector.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
visiblePercentageMax |
nested object |
A visibility trigger maximum percent visibility. Only valid for AMP Visibility trigger. | writable |
visiblePercentageMax.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
visiblePercentageMax.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
visiblePercentageMax.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
visiblePercentageMax.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
visiblePercentageMin |
nested object |
A visibility trigger minimum percent visibility. Only valid for AMP Visibility trigger. | writable |
visiblePercentageMin.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
visiblePercentageMin.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
visiblePercentageMin.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
visiblePercentageMin.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
waitForTags |
nested object |
Whether or not we should delay the form submissions or link opening until all of the tags have fired (by preventing the default action and later simulating the default action). Only valid for Form Submission and Link Click triggers. | writable |
waitForTags.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
waitForTags.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
waitForTags.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
waitForTags.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
waitForTagsTimeout |
nested object |
How long to wait (in milliseconds) for tags to fire when 'waits_for_tags' above evaluates to true . Only valid for Form Submission and Link Click triggers. |
writable |
waitForTagsTimeout.key |
string |
The named key that uniquely identifies a parameter. Required for top-level parameters, as well as map values. Ignored for list values. | writable |
waitForTagsTimeout.list[] |
list |
This list parameter's parameters (keys will be ignored). | writable |
waitForTagsTimeout.map[] |
list |
This map parameter's parameters (must have keys; keys must be unique). | writable |
waitForTagsTimeout.value |
string |
A parameter's value (may contain variable references such as "{{myVariable}}") as appropriate to the specified type. | writable |
Response
If successful, this method returns a Triggers resource in the response body.
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library.
/* * Note: This code assumes you have an authorized tagmanager service object. */ /* * This request creates a new trigger for the authorized user. */ // Create the condition parameters objects. Parameter arg0 = new Parameter(); arg0.setType("template"); arg0.setKey("arg0"); arg0.setValue("{{Page URL}}"); Parameter arg1 = new Parameter(); arg1.setType("template"); arg1.setKey("arg1"); arg1.setValue("timed.html"); // Create the auto event condition object. Condition condition = new Condition(); condition.setType("contains"); condition.setParameter(Arrays.asList(arg0, arg1)); // Create the event parameter. Parameter eventName = new Parameter(); eventName.setType("template"); eventName.setValue("gtm.timer"); // Create the interval parameter. Parameter interval = new Parameter(); interval.setType("template"); interval.setValue("10000"); // Create the limit parameter. Parameter limit = new Parameter(); limit.setType("template"); limit.setValue("10"); // Create the trigger object. Trigger trigger = new Trigger(); trigger.setName("Timer Trigger"); trigger.setType("timer"); trigger.setAutoEventFilter(Arrays.asList(condition)); trigger.setEventName(eventName); trigger.setInterval(interval); trigger.setLimit(limit); try { Trigger response = tagmanager.accounts().containers(). triggers().create("123456", "54321", trigger).execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } /* * The results of the create method are stored in the response object. * The following code shows how to access the created Id and Fingerprint. */ System.out.println("Trigger Id = " + response.getTriggerId()); System.out.println("Trigger Fingerprint = " + response.getFingerprint());
Python
Uses the Python client library.
# Note: This code assumes you have an authorized tagmanager service object. # This request creates a new trigger. try: response = tagmanager.accounts().containers().triggers().create( accountId='123456', containerId='54321', body={ 'name': 'Timed trigger', 'type': 'timer', 'autoEventFilter': [ { 'type': 'contains', 'parameter': [ { 'type': 'template', 'key': 'arg0', 'value': '{{Page URL}}' }, { 'type': 'template', 'key': 'arg1', 'value': 'timed.html' } ] } ], 'eventName': { 'type': 'template', 'value': 'gtm.timer' }, 'interval': { 'type': 'template', 'value': '10000' }, 'limit': { 'type': 'template', 'value': '10' } } ).execute() except TypeError, error: # Handle errors in constructing a query. print 'There was an error in constructing your query : %s' % error except HttpError, error: # Handle API errors. print ('There was an API error : %s : %s' % (error.resp.status, error.resp.reason)) # The results of the create method are stored in response object. # The following code shows how to access the created id and fingerprint. print 'Trigger Id = %s' % response.get('triggerId') print 'Trigger Fingerprint = %s' % response.get('fingerprint')
Try it!
Use the APIs Explorer below to call this method on live data and see the response.