Mobile app version of vmapp.org
Login or Join
Gonzalez347

: Tracking rotating Ads with Google Tag Manager So at the moment we have our ads setup using event tracking in Google Analytic (Universal) and they are implemented in this format: <a href="example.com"

@Gonzalez347

Posted in: #Advertising #EventTracking #GoogleAnalytics #GoogleTagManager #RegularExpression

So at the moment we have our ads setup using event tracking in Google Analytic (Universal) and they are implemented in this format:

<a href="example.com" onclick="ga('send', 'event', 'Banner Ad - Top', 'Click','Ad Title - (588x88)',1.00, {'nonInteraction': 1});"target="_blank"><img src="example.com/ads/ad_588x88.jpg" alt=""></a>


I would like to track these ads by position if possible because we have ads from same vendors displayed in multiple positions.

I am trying to wrap my brain around how I can implement something like this in Google Tag Manager. I assume this will involve some advanced rules with RegEx? Is it something that can be passed through the dataLayer?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Gonzalez347

1 Comments

Sorted by latest first Latest Oldest Best

 

@Candy875

You could add data-attributes to your ad link if you are using HTML5:

<a href="example.com" class="someclass" data-adposition="Banner Ad - Top" data-adnamesize="Ad Title - (588x88)" data-advalue="1.00" ><img src="example.com/ads/ad_588x88.jpg" alt=""></a>


Then add a new tag in Google Tag Manager for catching clicks on this kind of links (identified by "someclass" as an example). Tag name: Whatever-you-want-to-name-it; Tag Type: Custom HTML Tag.
Using JQuery you can extract data-attributes and pass them as parameters to ga function. Insert this snippet into HTML textbox. Obviously, you'll need to adjust the snippet as you need, based on what you use as class and data-attributes names.

<script type="text/javascript">
$( document ).ready(function() {
$( document ).delegate( "a.someclass", "click", function() {
try{
ga('send',
'event',
$(this).data('adposition'), //Event Category
'click', //Event action
$(this).data('adnamesize'), //Event Label
$(this).data('advalue'), //Event value
{'nonInteraction': 1}
);
}catch(err)
{
//do something if you need
}
});

});
</script>


Then add a Firing Rule that fires on every single page of your site, assuming you have those kind on links every where. Such rule should be like this

{{url}} matches regex .*




Update: Using GTM Link Click Listener

Assuming your links have data-attributes as my example above, you can do something like this:

Set up GTM Link Click Listener###

Add a new Tag.
Set Tag Name to whatever you want, maybe Link Click Listener.
Set Tag Type to Link Click Listener.
Add a Firing rule for all pages.





Set up click event tracking for your ad links

Add a new Tag.
Set Tag Name to whatever you want, maybe Ad Links Click.
Set Tag Type to Google Analytics => Universal Analytics or Classic Google Analytics, depends on what version you're using.
Insert your Web Property Id.
Set Track Type to Event; for Event Tracking Parameters you'll need to add macros to grab info from your ad links and set them into Event's parameters.

For event Category:
Click on the brick icon, then select New macro.
Set Macro Name to something like Ad Link Position.
Set Macro Type to Custom Javascript.
Insert this code into Custom Javascript textbox:

function(){
return {{element}}.dataset.adposition;
}


For event Action set whatever you want, maybe click.

For event Label:
Click on the brick icon, then select New macro.
Set Macro Name to something like Ad Link Name - Size.
Set Macro Type to Custom Javascript.
Insert this code into Custom Javascript textbox:

function(){
return {{element}}.dataset.adnamesize;
}


For event Value:
Click on the brick icon, then select New macro.
Set Macro Name to something like Ad Link Value.
Set Macro Type to Custom Javascript.
Insert this code into Custom Javascript textbox:

function(){
return {{element}}.dataset.advalue;
}


Maybe you don't want clicks to those ad links count as an interaction, then set event Non-interaction to true.





And here comes the magic, chain Ad Links Click to Link Click Listener:
Add a new Firing Rule for Ad Links Click tag.
Set Rule Name to something like Ads GTM Link Click Event.
Add a new Condition set {{event}} equals gtm.linkClick.
Add a second Condition set {{element classes}} equals someclass.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme