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 in GTM Template Gallery

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.

Configure VisitorAPI Tag in GTM

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”

Create Data Layer Variable in GTM

Here is a list of all the data layer variables created by the VisitorAPI tag:

Suggested Variable NameData Layer Variable NameDescription
IP AddressvisitorApiIpAddressThe IP address of the visitor.
Country CodevisitorApiCountryCodeCountry from which the visitor is located in as an ISO 3166-1 alpha-2 country code.
Country NamevisitorApiCountryNameThe full name of the country which the visitor is located in.
CurrenciesvisitorApiCurrenciesAn array of the official currencies of the country which the visitor is located in.
LanguagesvisitorApiLanguagesAn array of the official languages of the country which the visitor is located in.
RegionvisitorApiRegionName of the region, state or province which the visitor is located in. The complete list of valid region values is found in the ISO-3166-2 standard.
CityvisitorApiCityName of the city which the visitor is located in.
City LatLongvisitorApiCityLatLongLatitude and longitude of the city which the visitor is located in.
BrowservisitorApiBrowserThe browser name which the visitor uses.
Browser VersionvisitorApiBrowserVersionThe browser version which the visitor uses.
Device BrandvisitorApiDeviceBrandThe brand of the device which the visitor uses. Only applicable to mobile devices.
Device ModelvisitorApiDeviceModelThe model of the device which the visitor uses. Only applicable to mobile devices.
Device FamilyvisitorApiDeviceFamilyThe family of the device which the visitor uses. Only applicable to mobile devices.
OSvisitorApiOsThe operating system name of the device which the visitor uses.
OS VersionvisitorApiOsVersionThe operating system version of the device which the visitor uses.

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.

Create Custom Trigger Based on Visitor Data

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.