Sending more GTM event data without duplicating Tags - google-analytics

I collect video tracking data to data layer and I would like send all the data as a part of the same event.
dataLayer.push({
'event': 'video',
'EventCategory': 'HTML5 Video',
'EventAction': VideoProgressWatched,
'EventLabel': videoLink,
'EventContributor': videoContributor,
'EventVideoCategory': videoCategory,
'EventVideoDuration': videoDuration
});
I tried splitting this into few different Tags that are triggered by the same triggers.
Tag 1:
Event Category: {{EventCategory}},
Event Action: {{EventAction}},
Event Label: {{EventLabel}}
Tag 2:
Event Category: {{EventCategory}},
Event Action: {{EventAction}},
Event Label: {{EventContributor}}
Tag 3:
Event Category: {{EventCategory}},
Event Action: {{EventAction}},
Event Label: {{EventVideoCategory}}
But I somehow doubt this is the right way to do it. What would be the correct way of doing this?

Consider sending the additional data as hit-scoped custom dimensions, then on the GA side defining those Custom dimensions as things like "Event Contributor" etc.

Related

How do I view the values in Track_URL defined by Google Javascript events

This is the following event I am capturing in Google Analytics.
How do I view the event_label in Report or Explore options. What is the dimension that I need to select?
When I was viewing custom report/explore I simply done see any event category
gtag('event', 'Track_URL', {
'event_category': 'URL Tracking',
'event_label': window.location.href
});
Cannot find event_category dimension

google analytics not tracking custom dimension in context to events

I need to differentiate the users (Internal and External) who are performing some event action. so I am using the following code to track the user using custom dimension. My end goal is to know who performed the specific event by internal or external user
ga('send', 'event', 'Contract Change', 'click', 'Landing Page', 'My Value', {
'dimension3': 'External'
});
ga('send', 'event', 'Contract Change', 'click', 'Landing Page', 'My Value', {
'dimension3': 'Internal'
});
I have triggered this tracking code from javascript console for the testing purpose however it's not logging any data and I am not able to get the custom dimension value at any of the place.
I would change a couple of things:
Integers for event value: like Eike Pierstorff said, the event value has to be an integer. Technically you could leave the field out as it's optional, but it's best practice to assign values to your goal, so you can quantity the importance of user actions on your website:
https://developers.google.com/analytics/devguides/collection/analyticsjs/events#event_fields
Set dimensions before events: what you're doing should work, however it makes the code harder to read (most code formatting will break the {} syntax into 2 lines). Also, if you're sending multiple events which should be associated with the dimension, it's just cleaner to have the dimension declaration first, then all your events. Finally, if it's a user-scope dimension (internal vs. external users), it's more logical to declare the dimension before events, otherwise it looks like the dimension is hit-scope:
For instance:
ga('set', 'dimension3', 'Internal');
ga('send', 'event', 'Contract Change', 'click', 'Landing Page', 10);
ga('send', 'event', 'Other event with dimension', 'foo', 'bar', 20);

wpcf7 and GTM event listener issue

I have a Tag set up in GTM, custom html like this;
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
dataLayer.push({
'event' : 'wpcf7successfulsubmit',
'CF7formID' : event.detail.contactFormId
});
}, false );
</script>
Doesn't work. Not at all. So I put a script on the page.
var wpcf7Elm = document.querySelector( '.wpcf7' );
wpcf7Elm.addEventListener( 'wpcf7submit', function( event ) {
dataLayer.push({
'event' : 'wpcf7successfulsubmit',
'CF7formID' : event.detail.contactFormId
});
}, false );
from a basic example on contactform7.com. This, in GTM preview, triggers fine. The first time it triggers the tag once, the 2nd and subsequent times it triggers twice (implying that both my script and the GTM tag are firing). Guessing at a problem with the event bubbling up. I put the specific selector wpcf7Elm into the tag's custom html but this doesn't work - like the first example.
I have no problem with running from a script but the problem is firing the tag twice so that the analytics shows two events. I would like to use GTM but at the moment the only solution I can see is to go back to on page scripts.
Can anyone suggest what I might be doing wrong? Just to note that I have disabled all plugins and that I am using, on a different page, a wpcf7 event listener successfully (from a script on the page) to perform a presentation function.

Hard code GA event with GTM

I want to be able to hard code some GA event such as below. I'm using GTM and I understand its not possible in this way. Is there a way round this?
ga('send', 'event', 'Mobile', 'Original', 'App');
This is a problem because GTM creates a randomly named tracker instead of the default tracker (t0). You can either use the set fields method on the "name" field to set the tracker name to a known values (i.e. "myTracker") and adapt your calls accordingly:
ga('myTracker.send', 'event', 'Mobile', 'Original', 'App');
Or you can use the ge function to send your event tracking calls to all trackers in the page:
ga(function() {
var trackers = ga.getAll();
for (var i=0; i<trackers.length; ++i) {
var tracker = trackers[i];
tracker.send('event', 'Mobile', 'Original', 'App');
}
});
which will probably create more headache than it's worth. However it is unlikely that there is a scenario that can't be covered without a need to hardcode events - the proper way would be to push a custom GTM event (and your GA event data) to the dataLayer and trigger an GA event tracking call from there.
So for hardcoding event, just don't.
To implement ga event use this syntax wit your onclick.
replace ga('send', 'event', 'Mobile', 'Original', 'App');
with this and it will work:
gtag('event', 'click', {'event_category' : 'Mobile',
'event_action' : 'Original', 'event_label' : 'App'});

Google Analytics event tracking -Contact Form Submit

I am trying to track when a user clicks on the submit form button and they send contact information. I have this code on the contact page:
<input type="submit" value="Send" class="btn big btn_submit_form" onClick="ga('send', 'event', { eventCategory: 'Contact', eventAction: 'Information Request', eventLabel: 'Contact Form'});">
I am using Universal Analytics.
In my Google Analytics account, I have the goal description Name as Contact Form Submit, and the Goal Type is Event. The event conditions are as follows:
Category -Equals to- Contact
Action -Equals to- Information Request
Label -Equals to- Contact Form
with the Value field being left empty.
I have "Use the Event value as the Goal value for the conversion" set to yes.
However, Google Analytics doesn't seem to be tracking the event. Any idea how to fix this?
Thanks.
The most likely problem here is that your page is being unloaded before the event hit has time to send. When you submit a form on a web page, most browsers will stop executing JavaScript and start loading whatever new page the form's action attribute is pointing to.
The general workaround for this is to call preventDefault on the form's submit event, wait for the hit to successfully send to Google Analytics, and then manually re-trigger the form submit.
Here's how that might look (note: I'm using jQuery for simplicity):
$('#my-form').on('submit', function(event) {
// Prevent the browser's default form submission action.
event.preventDefault();
ga('send', 'event', {
eventCategory: 'Contact',
eventAction: 'Information Request',
eventLabel: 'Contact Form',
hitCallback: function() {
$('my-form').trigger('submit');
}
});
});
The key part in the above code is the hitCallback function, which gets invoked when GA returns success from the event hit beacon.
Maybe try changing the event to the form submit, instead of the button click:
<form onSubmit="ga('send', 'event', { eventCategory: 'Contact', eventAction: 'Information Request', eventLabel: 'Contact Form'});">
The form can be submitted in ways other than the clicking the submit button (for instance pressing enter in an input field)
Also, in my experience, the tracking will post correctly almost every time, even when you do not call preventDefault on the event.

Resources