Google Analytics Event Tracking onClick Code - google-analytics

I'm trying to set up event tracking on my web site but can't get it working correctly.
My tracking code:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-420xxxxxxx', 'mywebsite.org');
ga('send', 'pageview');
</script>
My event tracking code:
Purchase Details

You are mixing classic code with universal code. It will not work. You need to replace this:
_gaq.push(['_trackEvent', 'Button', 'Click', 'Purchase Details',, false]);
With this:
ga('send', 'event', 'Button', 'Click', 'Purchase Details');
GAJS reference for Events: https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation

Event hits can be sent using the send command. According to new analytics.js
Syntax:
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
For example if you want to track purchase event
ga('send', 'event', 'Button', 'Click', 'Purchase Details');
Here:-
eventCategory is Button. It is required field and its Value Type is text
eventAction is Click. It is required field and its Value Type is text
eventLabel is Purchase Details. It is optional field and its Value Type is text
eventValue is null. It is optional field and its Value Type is integer

it looks like you're using the new analytics.js instead of ga.js, so you'll want to use the proper event tracking method set:
ga('send', 'event', 'category', 'action');

Related

How to send event value on Google Analytics?

I can check category, action, and label on Google Analytics.
However, I can't seem to check the value so I am assuming the event value is not sent.
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('send', {
hitType: 'event',
eventCategory: 'ad',
eventAction: 'duration',
eventLabel: 'ad label',
eventValue: 20
});
Let me know if I am doing things wrong or any solution. Thanks!
The real time reports dont support the event value metric. You can see this in the Dimensions and metrics repport
You need to wait and check the behavior report.

Anatlytics - Two trackingIDs, only one get events

we have two tracking codes on our site. On both codes we get tracking of visitors and stuff correct, but when it comes to events, only one is getting the event even tho' we're sending it to both codes.
This is the setup:
ga('create', 'UA-12345678-6', 'auto');
ga('create', 'UA-123456-4', 'auto', 'clientTracker');
ga('require', 'displayfeatures');
ga('clientTracker.require','displayfeatures');
ga('require', 'ecommerce', 'ecommerce.js');
ga('clientTracker.require','ecommerce','ecommerce.js');
ga('send', 'pageview');
ga('clientTracker.send', 'pageview');
and this is the event:
$("#desktopCheckout").on("click", function() {
ga('send', 'event', 'test', 'clickOnCheckout');
ga('clientTracker.send', 'event', 'test', 'clickOnCheckout');
});
The event is being sent to the regular tracking code, but not to the "clientTracker".
Are we doing something wrong here?
GA Debug extension and Tag assistant extension in Chrome both shows that the event is being sent, and I've checked the tracking ID so it is correct. Just somehow Google Analytics is not recieving this.

Google Analytics Event tracking for Goals

I am having an issue in using the Google Goals for my My Event Tracking. I have added Google even tracking code to my web page. However, I cannot check for any conversions in my Google Goals but the event result can be shown in the Google Analytic --> Behavior --> Events Overview.
My Code is below
` <script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-87810245-1', 'auto');
ga('send', 'pageview');
</script>
<script>
$('#contact-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() {
$('contact-form').trigger('submit');
}
});
});
</script>`
Code for my Submit Button:
<input type="submit" id="submit" value="Validate and Submit" onclick="ga('send', 'event', 'form', 'submit', 'order sent', 10);"/>
My Google Goals:
enter image description here
Google Analytics Events Overview:
So you've got two events going on, one for the click of the submit button (to track intent perhaps) and one for the form submission itself. Your goal is configured to expect a value Greater than 10, but your form submission event is not passing a value in. You should either add a value (greater than 10), or remove the value from the goal configuration. Also your screenshot shows likely just the click event (since there's a value of 10 associated with it), but you'd probably be more interested in the actual submissions themselves.

Google Analytics shows too many pageviews

I have a strange issue with google Analytics on a website. This site normally has about 1000 - 1500 pageviews / day (and approximately 500-600 unique users).
Since a week analytics measures between 5000 and 15000 pageviews / day, but the unique users remains unchanged. I have never had so many pageviews / day in the last 2 years, so this values can't be correct.
I checked my Chrome network panel and noticed that http://www.google-analytics.com/collect?xxxx is triggered to often. Nothing has changed on the site, so what could cause such a behaviour?
An other problem is my bounce rate. Before I updated to Universal Analytics I used the following code to trigger an event gaq.push(['_trackEvent', 'Category', 'Action', undefined, 50, true]); ("true" to signalize a non-interaction-event).
After the update I used
ga('send', 'event', 'xxx', 'xxx', 'xxx');
The bounce rate decreased to 0% (the events has been counted as "interaction-event").
I found the notice to use the following ga('set', 'nonInteraction', true); to set the non-interaction flag. But where should I use this?
Should I start with the analytics code to track the pageview
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx-xx', 'example.com');
ga('require', 'displayfeatures');
ga('send', 'pageview');
then set the non-interaction-flag
ga('set', 'nonInteraction', true);
and at the end trigger an event in my page content
e.g. onload="ga('send', 'event', 'xxx', 'xxx', 'xxx');"
?
see eventTrackerGuide.
non-interaction (optional)
A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation
Every hit after the code ga('set', 'nonInteraction', true); will be a non-interaction hit.
If you want make a specific hit to non-interaction, just add non-interaction option on the hit. For example: ga('send', 'pageview', {'nonInteraction': true});
Try:
ga('send', 'event', 'xxx', 'xxx', 'xxx', undefined, true);
undefined - if you don't have a value of event

Universal Analytics Google - Custom dimensions

What's the difference between
ga('send', 'pageview', {
'dimension1': 'data goes here'
});
and
ga('set', 'dimension1', 'data goes here');
ga('send', 'pageview');
Doesn't it accomplish the same thing?
If you limit the answer the way you framed your question there is no difference at all.
The difference is that when you use set that custom dimension will be sent with every hit in the current page. Here's a better example:
1) In this example the pageview has the custom dimension attached but the event does not.
ga('send', 'pageview', {
'dimension1': 'data goes here'
});
ga('send', 'event', 'Category', 'Action');
2) In this second example both the pageview and the event have the custom dimension attached.
ga('set', 'dimension1', 'data goes here');
ga('send', 'pageview');
ga('send', 'event', 'Category', 'Action');

Resources