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

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');
});

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');

Related

Contact Form 7 with Google Analytics - gtag event tracking (Goals)

I am trying to set up event tracking with Contact Form 7 in Google Analytics. Google Tag Assistant seems to see the event but it does bot seem to be tracking in Google Analytics. Please see below:
document.addEventListener('wpcf7mailsent', function(event) {
gtag('config', 'UA-********-*', {
'send_page_view': false
});
// https://developers.google.com/gtagjs/reference/api#event
gtag('event', 'form_submitted', {
'event_category': 'lead',
'event_action': 'Submit',
'event_action': 'Form',
'event_value': 1,
});
console.log('Form Submitted');
}, false);
Goal Set Up
Google Tag Assist
You have several errors in your event code (for example you have written the action twice) however the construct is wrong since the syntax for send an event in gtag is the following:
gtag('event', <action>, {
'event_category': <category>,
'event_label': <label>,
'value': <value>
});
https://developers.google.com/analytics/devguides/collection/gtagjs/events
So you have to change you code like this:
gtag('event', 'Submit', {
'event_category': 'form_submitted',
'event_label': 'Form',
'value': 1
});

No data in Google Analytics (GTM ecomerce setup)

I have problems organizing a proper GTM debugging for a new project. I was trying to setup a basic tag from their docs, using:
<script>
// Measure a view of product details. This example assumes the detail view occurs on pageload,
// and also tracks a standard pageview of the details page.
dataLayer.push({
'event': 'gtm.load',
'ecommerce': {
'detail': {
'actionField': {'list': 'Apparel Gallery'}, // 'detail' actions have an optional list property.
'products': [{
'name': 'Triblend Android T-Shirt', // Name or ID is required.
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray'
}]
}
}
});
console.log("Pushed");
</script>
as tracking code, and also setting up the basic GTM tag, as suggested by the example: https://developers.google.com/tag-manager/enhanced-ecommerce#details
And using the Window Loaded event type for trigger.
The gtm debugger shows that events are triggered.. But nothing appears in google analytics.
I was also checking, if some messages are being sent to GA using the firebug, and looks like they are sent:
Sent beacon:
v=1&_v=j47d&a=681300097&t=pageview&_s=1&dl=http%3A%2F%2F192.168.0.107%2F%3Fproduct%3Dtest-product&ul=en-us&de=UTF-8&dt=test%20product&sd=24-bit&sr=1366x768&vp=1351x415&je=0&fl=22.0%20r0&_u=SCCAAAALI~&jid=&cid=247695807.1477915334&tid=UA-73812011-1&gtm=GTM-TWQ9DJ&pal=Apparel%20Gallery&pa=detail&pr1nm=Triblend%20Android%20T-Shirt&pr1id=12345&pr1pr=15.25&pr1br=Google&pr1ca=Apparel&pr1va=Gray&z=280618779
There are a couple of options here, depending on how much control you have with the page code. If you have full control, and if you want you load the ecom data on page load, then you do a dataLayer declaration with that data just before your GTM container:
dataLayer = [{
'ecommerce': {
'detail': {
'actionField': {'list': 'Apparel Gallery'}, // 'detail' actions have an optional list property.
'products': [{
'name': 'Triblend Android T-Shirt', // Name or ID is required.
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray'
}]
}
}
}];
Doing it this way allows you to capture the data on page load with your pageview tag.
You shouldn't do it with an event push, not especially with an event named gtm.load as that is the built-in event that gets pushed when the page assets have completely loaded, so you are probably not seeing data as there is a conflict with your 'page load' since there are now two gtm.load events being pushed.
If you still prefer an event, then just use a different name, eg. myEvent, and then create an event tag to fire on that event.
Lastly don't forget to enable your tag to use the dataLayer in order to capture the ecom info.

Can I capture div#Id and put in Google Analytic Event

Can I do like this
var eLabel = $('#example_placeholder').html();
and put eLabel into this
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'cash', // Required. privilege acquisition creditcard installment
'eventAction': 'ClickView', // Required.
'eventLabel': eLabel
});
Yes, you can do that. You can shorten things like this as well:
ga('send','event','cash','ClickView',$('#example_placeholder').html());

Google Analytics Enhanced Ecommerce - Track Product View with 'event' rather than 'pageview'

Is this acceptable? Calling the pageview in the header, and then sending an event(s) further down the page?
//head
ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');
ga('send', 'pageview');
//inside product details/body
ga('ec:addProduct', {
'id': 'P12345',
'name': 'Android Warhol T-Shirt',
'category': 'Apparel',
'brand': 'Google',
'variant': 'black'
});
ga('ec:setAction', 'detail');
ga('send', 'event')
Would this be better practice?
//head
ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');
//inside product details/body
ga('ec:addProduct', {
'id': 'P12345',
'name': 'Android Warhol T-Shirt',
'category': 'Apparel',
'brand': 'Google',
'variant': 'black'
});
ga('ec:setAction', 'detail');
//somewhere near footer
ga('send', 'pageview');
Yes, your suggested ga('send', 'pageview') at the bottom is the correct way.
Since you "know" when you render the page that the visitor will see the product detail page you might as well send it with the page view.
Use an event to send enhanced ecommerce tracking that hasn't happened when the page renders, like if the visitor adds the product to their cart. Use a non-interaction event to make it not affect bounce rate (and as suggested above, you should specify a category and an action for your event).
In terms of the syntax for the event push, when you send an event to GA, you have to include the category and action (as specified here https://developers.google.com/analytics/devguides/collection/analyticsjs/events). So you would have in your event push:
ga('send', 'event', 'eventCategory', 'eventAction');
Your eCommerce transaction looks fine.
Not sure about the strategy of sending an event with your pageview though. Usually an event is associated with some action (like a button or link click).
Hope this helps.

Is it possible to track custom metrics on interaction events instead of on pageview?

I would like to create the custom metric "rating" and send it on a click event along with a rating value. What am I doing wrong?:
var ratingValue = '5';
ga('send', 'event', 'button', 'click', 'rating', {
'nonInteraction': 1,
'page': window.location.href,
'rating': ratingValue
});
Reference to docs:
https://developers.google.com/analytics/devguides/collection/analyticsjs/events
You need to do two things:
In Google Analytics, create a new Custom Metric (admin > custom definitions > custom metrics).
In your event, specify the metric you are sending to rather than the name of the metric:
var ratingValue = '5';
ga('send', 'event', 'button', 'click', 'rating', {
'nonInteraction': 1,
'page': window.location.href,
'metric1': ratingValue
});

Resources