1

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?

2

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.

New Tag Link Click Listener
Firing Rule for Link Click Listener
Link Click Listener Tag

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.

Ad Links Click

Macro with Custom Javascript

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.

Ads GTM Link Click Event

  • Can't I just create link click listener and then create a custom HTML tag that include the dataLayer push of the event? – dasickle Jul 10 '14 at 22:06
  • @dasickle Sure, you can use GTM Link Click Listener for firing GA Events when clicking any link. The important thing is to "grab", from somewhere, data to be passed as parameters to GA Event. – Binarysurf Jul 13 '14 at 19:10
  • YOU ROCK MAN! Thanks a bunch for the examples. I am finally starting to make sense of how GTM works. The snapshots with the step by step really helped. Let me see if I can set if I could setup some events for other thing on my own using your example. If not I'll post again. – dasickle Jul 14 '14 at 21:54
  • @dasickle You're welcome, it's great to know my answer helped you. – Binarysurf Jul 14 '14 at 22:05
  • I was able to set most of my events up. One is giving be trouble. I posted the question webmasters.stackexchange.com/questions/67139/… – dasickle Jul 17 '14 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.