byron
byron

Reputation: 994

Is it possible to associate events with campaigns in Google Analytics (Universal)

We're using events to track impressions and clicks on campaign elements (carousel images, sidebar ads and footer banners). We're trying to associate each of those events with a Campaign so that we can report on campaign-specific events. It's not working. Events are created, but they are not associated with a campaign.

The documentation for events using analyitcs.js (https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation) seems to suggest that we can add additional attributes to events using the Field Reference: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference

Our event creation code is as follows:

   $('#campaignImage').on('click', function() {
     ga('send', {
      'hitType': 'event',
      'eventCategory': 'Promotions',
      'eventAction': 'Click',
      'eventLabel': 'IMAGE_TITLE',
      'page': window.location.pathname,
      'campaignName': 'CAMPAIGN_NAME'
     });
   });

Events are created successfully, but are not associated with the specified campaign (they all show up with campaign as "not set"). Is it even possible to do what we're trying to do, or is it only possible to track traffic acquisition for campaigns using URL parameters?

UPDATE - SOLUTION BELOW

Based on a recommendation from Blexy

We switched to use Advanced eCommerce...setup described here

Our code, simplified:

$( document ).ready(function() {

  //Promotion clicks
  $('.promo-img').on('click', function() {
    ga('ec:addPromo', {              
        'id': $(this).attr('data-campaign'),
        'name': $(this).attr('data-campaign'),
        'creative': $(this).attr('data-unitname'),
        'position': $(this).attr('data-position')
    });
    ga('ec:setAction', 'promo_click');    
    ga('send', {
        'hitType': 'event',
        'eventCategory': 'Internal Promotions',
        'eventAction': 'Click',
        'eventLabel': $(this).attr('data-unitname'),
        'pageview': window.location.pathname
    });
  });

});

$(window).load(function(){

  //Promotion impressions
  if ($('.promo-img').length > 0) {
    ga('ec:addPromo', {
        'id': $('.promo-img').attr('data-campaign'),
        'name': $('.promo-img').attr('data-campaign'),
        'creative': $('.promo-img').attr('data-unitname'),
        'position': $('.promo-img').attr('data-position')
    });
  }

  ga('send', 'pageview');

});

Upvotes: 2

Views: 858

Answers (1)

Nick Blexrud
Nick Blexrud

Reputation: 9603

I don't believe what your attempting is going to work, as the event creation code is only going to accept its specific parameters.

However, I do think what you're trying to do is possible using Enhanced Ecommerce - Measuring Internal Product Promotions.

For example, you could pass this event when an ad is shown:

ga('ec:addPromo', {               // Promo details provided in a promoFieldObject.
  'id': 'PROMO_1234',             // Promotion ID. Required (string).
  'name': 'Summer Sale',          // Promotion name (string).
  'creative': 'summer_banner2',   // Creative (string).
  'position': 'banner_slot1'      // Position  (string).
});

And this click code when an ad is clicked:

// Identify the promotion that was clicked.
ga('ec:addPromo', {
  'id': 'PROMO_1234',
  'name': 'Summer Sale',
  'creative': 'summer_banner2',
  'position': 'banner_slot1'
});

// Send the promo_click action with an event.
ga('ec:setAction', 'promo_click');
ga('send', 'event', 'Internal Promotions', 'click', 'Summer Sale');

Upvotes: 5

Related Questions