Google Analytics Single Application Issue - google-analytics

I have setup google analytics on a small 1 page application website with 3 sections. I have implemented page fields and tracker object. However, every page title in google analytics is coming across as "Contact" although I have designated page titles for each pageview as below:
ga('create', 'UA-50789730-1', 'auto');
ga('set', {
page: '/',
title: 'Home'
});
ga('set', {
page: '/#features',
title: 'Features'
});
ga('set', {
page: '/#download',
title: 'Download'
});
ga('set', {
page: '/#contact',
title: 'Contact'
});
ga('send', 'pageview', '/');
ga('send', 'pageview', '/#features');
ga('send', 'pageview', '/#download');
ga('send', 'pageview', '/#contact');
Am I doing something wrong here?
Thanks!

Whenever you call set you're overriding the previously set data. That's why "Contact" is all you're seeing for the title in the code shown above, since that set call overrides the previous two.
I'd recommend reading the analytics.js overview to get a better idea of how the underlying library works:
https://developers.google.com/analytics/devguides/collection/analyticsjs/
Then once you have a better understanding, you should read the guide on tracking single page applications, as there are some gotchas you should be aware of:
https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications

Related

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 for Single Page Application with # views

I'm trying to implement Google Analytics on Single Page Application. I'm trying to use Autotrack to track the virtual page views. But, it's not working.
Code:
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXX-1', 'auto');
ga('require', 'urlChangeTracker', {
shouldTrackUrlChange: function(newPath, oldPath) {
newPath = newPath.split('?')[0];
oldPath = oldPath.split('?')[0];
return newPath != oldPath;
}
});
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<script async src="https://cdnjs.cloudflare.com/ajax/libs/autotrack/0.6.4/autotrack.js"></script>
Quoting from related github issue:
"The urlChangeTracker plugin does not support tracking URL hash changes. This is mentioned in the overview section of the plugin documentation.
Since almost all browsers in use today support the History API, that's what you should be using when creating SPAs. Hash changes should only be used for in-page navigation to anchor links."

How do I set appVersion for Google Analytics Event tracking

When I try to set the appVersion in google analytics, then my event tracking stops working. Specifically, I'm trying to include the app version with event tracking so I can know which version of the app caused an event.
I've tried setting the app version like this:
ga('set', 'appVersion', app.version);
I've tried like this:
ga('send',
'event',
eventCategory,
eventAction,
{'page': pageName, 'appVersion' : app.version });
And I've also tried the alternative syntax:
ga('send',
{'hitType' : 'event',
'eventCategory' : eventCategory,
'eventAction' : eventAction,
'page' : pageName,
'appVersion' : app.version});
If I include appVersion, then event tracking stops working. No events show in realtime and no show the next day in the Behavior/Events section. The PageViews still work though.
As requested in the comments, I am editing to add in my event tracking code. It's been through several variations while I tried solve this problem. Here's what it looks like currently.
var app = {
trackEvent: function (pageName, eventCategory, eventAction, optionalEventLabel, optionalEventValue) {
var eventObject = {
'eventCategory' : eventCategory,
'eventAction' : eventAction,
'optionalEventLabel' : optionalEventLabel,
'optionalEventValue' : optionalEventValue,
'page' : pageName,
};
console.log("app.trackEvent - " + JSON.stringify(eventObject));
ga('send', 'event', eventObject);
}
}
I call this method from many places using a call like:
app.trackEvent("PageNameValue", "EventCategoryValue", "EventActionValue", "EventLabelValueIfIHaveOne", AnIntegerValueIfIHaveOne);
Any help or suggestions will be greatly appreciated.
Edit...
I found the following bug report that seems to apply: https://code.google.com/p/analytics-issues/issues/detail?id=366
The bug reporter mentions solving this problem by setting up a custom dimension. I will give that a try.
This appears to be be a Google Analytics bug. See https://code.google.com/p/analytics-issues/issues/detail?id=366 for more information.
As suggested by the bug reporter, the workaround is to use a custom dimension that you define in the Admin / Custom Definitions / Custom Dimensions section of the Google Analytics console.
Click "New Custom Dimension"
Enter name ( I entered customAppVersion )
Choose scope ( I chose Hit )
Click Create
Google will then suggest code examples for you, like...
var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension1', dimensionValue);
The only thing in the code sample that you need to change is the value of 'dimensionValue'. So I ended up with the following code.
ga('create', 'UA-########-#', 'auto');
ga('set', 'checkProtocolTask', null); // Disable file protocol checking (so that GA will work on Android devices)
ga('set', 'dimension1', app.version);
ga('send', 'pageview');
After this, the custom dimension will be applied to each hit recorded by Google Analytics and you can use that custom dimension to filter your results in the Google Analytics console.
As per google
Since the appName field must be sent with all app hits, it's often
best to set that field on the tracker itself using the set command or,
alternatively, when the tracker is created:
ga('create', 'UA-XXXXX-Y', 'auto', {
'appName': 'myAppName'
});
// The `appName` field is now set on the tracker, so
// screenview hits don't need to include it.
ga('send', 'screenview', {appVersion: '1.2'});
// Sending multiple parameters
ga('send', 'screenview', {appName: 'com.company.app', appVersion: '1.2'});
More information here
It works if you set at least the "appName", it's a good practice to set "appName" and "appId" before to set "appVersion"
ga('set', 'appId', app.id);
ga('set', 'appName', app.id);
ga('set', 'appVersion', app.version);

add Meteor DocHead => DocHead.loadScript with Flow-router-ssr.

Can't figure out how to add the analytics code using DocHead.loadScript . Documentation assume that you more or less already understand it.
Have been trying in component, Client etc. Manage to get DocHead.setTitle(title); etc to work without problem.
Where do i add this DocHead.loadScript to make it work?
var gaScript = 'https://www.google-analytics.com/analytics.js';
DocHead.loadScript(gaScript, function() {
// Google Analytics loaded
ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');
});
Github: https://github.com/kadirahq/meteor-dochead

GA Tracking Event in WordPress

I want to integrate GA Tracking Event on buttons in WordPress. Currently my theme is using ShortCodes and I can add specific .Class to it.
[vc_button text="Order Now" type="blue" align="left" url="#" size="big" class="ordernow"]
Google Analytic code is added on the site which is on Local Host and it's working. I found an article on this but don;t know what I'm missing.
http://www.gravitatedesign.com/blog/event-tracking-google-analytics-wordpress-edition/
There will be around 4 buttons of "Order Now" on a single page and I want to track their conversion rate with Google Analytic so I will know on which button visitors are getting engage. Hope this will deliver the exact thing that I want to achieve..
please provide your result html of that buttons.
I usually use something like this
$('.ordernow').on('click', function(e) {
ga('send', 'event', 'order', document.URL);
});
you can add additional classes to track each button, example:
$('.ordernow button1').on('click', function(e) {
ga('send', 'event', 'order1', document.URL);
});
$('.ordernow button2').on('click', function(e) {
ga('send', 'event', 'order2', document.URL);
});
hope this will help you.

Resources