How To Fire DoubleClick Counter Tags For Multiple Countries/Languages More Efficiently In GTM
This post is a combination of my two threads opened on Google Tag Manager forum. Both were answered by Simo Ahava and explains how to do this [Always helpful!].
So we have a multi country/lang website that has DoubleClick counter tags on it [6 countries/up to 3 languages - EN/AR/FR]. With DoubleClick tags created specifically for each market/lang, creating individual triggers for each lang/market can make GTM triggers/tags section look messy. More importantly, if the 6 countries were now expanded to 10-20 countries, would you continue creating 1 trigger per DC tag? hmmm, nope!
Here's an example of the DC tags structure for just AE/EN site
The DoubleClick counter tags are setup to fire on brochure downloads. An example of a trigger would be:
if page path matches regex /ae/en/
and click url matches regex /brochure.pdf
then fire DoubleClick tag corresponding to Brochure Download for this particular market + lang.
Here's how the DC tag would look like in GTM.
How to setup DoubleClick counter tags for multiple countries/languages in GTM
Step 1: Getting the country name and language of the page being accessed.
Here's my first thread on GTM forum asking about how to scoop the country name / lang from the page path and store it as a variable: https://productforums.google.com/forum/#!topic/tag-manager/nCgNpdRhaR4;context-place=topicsearchin/tag-manager/authorid$3AAPn2wQcoU-Azf0LsKlh6uHfYaSXH0hjoRDDwomZ0MCRNUL9Z7--q74gHU6hcPyRk3OS93PLJsUtZ%7Csort:date%7Cspell:false
Simo's respone to this was to create two JS variables:
JS variable to scoop country name:
function() {
return document.location.pathname.split('/')[1];
}
JS Variable to scoop language:
function() {
return document.location.pathname.split('/')[2];
}
Since the url taxonomy is www.site.com/countrycode/langcode/page.html or www.site.com/ae/en/page.html, using document.location.pathname.split finds the first /and then saves the value (in this case, 'ae' as a string). The second JS variable finds the next '/' in the url and saves it as 'en' - again as a string.
So, having the country name and language currently being viewed as variable values takes care of the parameter - when to fire which tag.
Step2: Associating the right DoubleClick tag for each market/lang.
Here's the second thread
In this particular DC tag example, the advertiser ID was common for all sites, only type= and cat= parameters changed between individual DC tags. Creating one JS variable for each dynamic value, we would have 6 JS variables,
Brochure download type JS variable.
Brochure download cat JS variable.
Tel clicks type JS variable.
Tel clicks cat JS variable.
Emails sent type JS variable.
Emails sent cat JS variable.
Example, brochure download type= JS variable.
function() {
var country = {{country variable}};
var language = {{language variable}};
if (country === 'ae' && language === 'en') return 'type=string value for ae/en DC tag';
if (country === 'ae' && language === 'ar') return ...;
return undefined;
}
In the above JS variable, the var country and language were solved in the first part of the thread. That's why in this variable, we've used a dynamic value of {{country variable}}...in the following lines, the script then checks if the values pulled in country/language variables matches both conditions. IF yes, return a type= string value that's specific to the particular DC tag.
Once this is done, you can go to the Brochure Download DC tag in GTM and in the Group tag string (type=) parameter, enter the dynamic tag value {{Brochure download type value}}, same for Activity tag (cat=) parameter, {{Brochure download cat value}}.
Something like this:
Hope this post makes it easier for others. Big thanks to Simo for answering these questions on GTM forum.