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');
});
setmethod before thesendto set campaign stuff. Note that GA will not track campaigns unless you at least setcampaignName,campaignSource, andcampaignMedium- Crayon Violent