Track country, city and other geo data of the current visitor
Google Tag Manager for WordPress can add various geo data into the data layer about your current visitor. Depending on your website’s traffic, additional fees may apply IP Stack. There is one exception in the list of variables: geoCloudflareCountryCode does not require to use IP Stack and has a separate checkbox in plugin option to activate. See details below.
You can place a cookie named block_gtm4wp_geoip
into the browser of your visitor to prevent the GeoIP usage in the browser for that particular user. This is useful as the IP address of your site visitor will be shared with those 3rd party services and it is a good practice to get consent from the user to do that. If the user denies the consent, create the block_gtm4wp_geoip
cookie using any of the following values: "yes"
, "true"
, "on"
or "1"
.
Once API keys have been set in GTM4WP plugin options (you can obtain the keys by registering for a free or paid plan at IP Stack), the following data layer variables will be available:
geoFullGeoData
The full API response of IP Stack. Available data is listed in the IP Stack documentation.
geoCountryCode
If you just need the country code from geoFullGeoData, you can use this data layer variable. It uses ISO-3166-1 codes.
geoCloudflareCountryCode
This data layer variable is an exception from the other variables: if your site is protected by Cloudflare, you can access the country code provided by Cloudflare in the HTTP headers. To use this option, you need to turn on a separate option in GTM4WP and you do not need to use IP Stack.
geoCountryName
If you just need the country name from geoFullGeoData, you can use this data layer variable..
geoRegionCode
If you just need the region code from geoFullGeoData, you can use this data layer variable (e.g. CA
for California).
geoRegionName
If you just need the region name from geoFullGeoData, you can use this data layer variable (e.g. California).
geoCity
If you just need the name of the city from geoFullGeoData, you can use this data layer variable.
geoZipcode
If you just need the zipcode from geoFullGeoData, you can use this data layer variable.
geoLatitude
If you just need the latitude attribute from geoFullGeoData, you can use this data layer variable.
geoLongitude
If you just need the longitude attribute from geoFullGeoData, you can use this data layer variable.