Google Tag Manager Integration
This article provides details on how to implement VisitorAPI in Google Tag Manager to trigger tags based on visitor data such as location and device.
Step 1: Import VisitorAPI tag template
First, in Google Tag Manager workspace, click on “Templates”, then click on “Search Gallery” as the instructions below:
Search for VisitorAPI and you will find the VisitorAPI from us.
Import the VisitorAPI tag template into your Google Tag Manager workspace.
Step 2: Create a VisitorAPI tag
Create a new tag in the Google Tag Manager workspace, and select VisitorAPI under “Custom” as the tag type.
You will need your VisitorAPI project ID from the VisitorAPI project dashboard. Copy and paste the ID to the Project ID field in the VisitorAPI tag configurations, and set the triggering condition as the pages you will need the location and device data for other tags.
The VisitorAPI tag will fetch the visitor’s location and device data and push the data into the dataLayer.
Step 3: Create Google Tag Manager variables
To use the data, create variables in Google Tag Manager to map the data in dataLayer. When creating the variables, choose Data Layer Variable, then map the new variable to one of the data layer variable created by the VisitorAPI tag. The example below maps the visitorApiCountryCode to “Country Code”
Here is a list of all the data layer variables created by the VisitorAPI tag:
Once the variables you need are created, you can use them as trigger conditions in other tags.
Step 4: Create triggers for tags
When you create tags that needs the location and device as triggering conditions in Google Tag Manager, set the trigger conditions based on event “visitor-api-success” so that the tag will be trigger when the VisitorAPI tag successfully fetch the data, and set the trigger based on the variables. Below is an example of a trigger for visitors form the US only.
Step 5: Authenticate the domain
VisitorAPI authenticate the API calls based on calls’ referral domains. That means, before you use the API on a domain, you must put the domain in the VisitorAPI settings to open the API to accept requests from the domain. See Authentication documentation for details.