Google analytics _trackSocial not working - google-analytics

I have correctly included the GA tracking code snippet found here (http://support.google.com/analytics/bin/answer.py?hl=en&answer=1008080&rd=1) and it is working (& has been for years)
I have recently set up the Facebook Javascript SDK for running code when the 'like' button is clicked - this also works.
In the same FB.Event function, I included googles _gaq.push _trackSocial as follows...
FB.Event.subscribe('edge.create',
function(response) {
// do some stuff, this is working.
// google track likes - this isn't working
_gaq.push(['_trackSocial', 'facebook', 'like']);
}
);
No errors in console.
So either analytics takes a long time to register the likes & I haven't waited long enough or something is wrong.
Since the FB.Event & my JS functions ARE WORKING & _gaq.push does not give any errors - I am unsure what the problem is.
In Google Analytics Traffic Source > Social > Social Plugins then click on the 'Social Source' tab & it shows only Google.

24 hours later the answer is evidently that Analytics takes a long time to update.
Although I have not changed anything Analytics is now showing Facebook as a Social Plugin.
So it just takes a really long time to show up in analytics.

If you're using the 'newer' analytics.js vs the legacy ga.js version you need to use ga('send'...) instead of _gat.push(...).
I would have expected you to get an error in your situation, but this may help others.
ga or _gaq.push for Google Analytics event tracking?
If you're trying for instance to use the social-tracking.js from StuffedWeb alongside analytics.js then you'll need to convert it to the new call style.

Related

Custom dimension not being set

I've got myself a bit of a head scratcher here, for me anyway, as I'm a bit new to all this.
I have WP a site that has its GA snippet inserted with Google Site Kit.
There is a plugin that, when a user registers, sets the users ID to a custom dimension.
The code to execute this 'set' has been added to the WP footer with the add_action('wp_footer') command.
The code looks like this:
<script type=\"text/javascript\" id=\"set-google-id-dimension\">
document.addEventListener(\"readystatechange\", event => {
if (event.target.readyState === \"complete\") {
try{
gtag('event', 'registration', {'dimension1': '".$client."'});
}catch(e){
try{
ga(function() {
// Logs an array of all tracker objects
var trackers = ga.getAll();
var firstTracker = trackers[0];
console.log('tracker: '+firstTracker.get('name'));
ga(firstTracker.get('name')+\".set\",\"dimension1\" ,\"".$client."\");
});
}catch(e){
console.log('GA and GTAG not defined');
}
}
}
});
</script>
For ease of reading, I've stripped out the PHP, but this is being echoed out in the footer.
Why the GTAG and GA command? Both analytics are being output in the console, though the site owner does not know why as "they only use Google Site Kit".
Now, this code works on the dev site that I control (and I've set it up to mimic the live site as best as possible):
However, when on the "live" site, the dimension is never set, even though I can see the 'set' command being executed (ignore the timestamps in the console, I forgot to screenshot before navigating away from the site and had to go back and reload the page):
The live site does not use the default tracker, hence the ga.getAll() call to access the tracker information.
From what I can see, everything should work fine.
I understand that from reviewing this question
Google Analytics Custom Dimension Not Being Set
that the 'set' needs to come before the 'send'.
I'm not sure how to accomplish this though since the plugin does not send the pageview to GA, from what I understand, that's Google Site Kit. I have contemplated adding a 2nd pageview send when this plugins code is loaded (it is only executed immediately after a registration and never again), but that would skew the page hits.
This site has had a myriad of "admins" over the years, so I wouldn't be surprised if there was something buried in one of the plugins causing a conflict somewhere. At one point I thought it was a timing issue, so I had the function load every 50 milliseconds checking for 'ga' to be defined, then execute the 'set' command (with a limit to 35 iterations), but the issue was the same (could set the command execute in the console, but the dimension did not reflect the value).
Any advice I can get to debug and get to the root cause would be of great assistance to me. Please ask any questions you need and I will respond as quickly as possible.
It seems a bit complex as a situation so understanding how it works and why there is gtag and ga at the same time is not easy to understand.
In any case, assuming that everything is working, what you can do is not to send a second pageview but send a dedicated event (by setting non-interaction to true) in this way you do not alter any information in Google Analytics and you can pass to the platform the data you are interested in (dimension1).

GTM and Enhanced Ecommerce. Not showing in Analytics - Scraping DOM for DataLayer

I'm having a nightmare trying to get enhanced eCommerce data showing in Google Analytics. Using Tag manager I've got the below in my data layer but I can't see anything in my Google Analytics account.
Unfortunately at the moment I'm having to scrape the DOM for the relevant information, so I'm pushing all the information to the datalayer with a 'payment ' event. The corresponding tag is correctly firing on this event.
The GTM preview inspector is showing everything as I would expect
I have ticked the relevant enabled enhanced eCommerce boxes and waited 72 hours after each attempted change but still no luck - can anyone help? I'm sure I've missed a simple step somewhere but no luck on the Google developer docs.
Many Thanks,
Eoghain
'Payment' Event:
After page Fully Loaded:
Tag:
Trigger:
OK I believe the issue is because you are using the Transaction type tag. This applies only to standard e-commerce. You need to piggyback your e-commerce data with either a pageview or a (non interactive) event.

Google Analytics - Overriding Default Values

I am trying to confirm a 'pageview' is being processed properly.
( using google real time dashboard ).
The issue is simple, If I use this call:
// page uri is: www.example.com/signup
ga( 'send', 'pageview' );
I see a matching entry at google's dashboard.
Attempting to override the title / page parameters ( according to the docs ) like so:
ga( 'send', 'pageview', {
'page': '/admin/logout',
'title': "test"
} );
Simply produces nothing over at google's side.
Any idea what is going on?
EDIT
It appears that google analytics service is filtering pages that contain
the word "admin".
Removing that from the 'page' helped in my case.
I don't know what's going on because your syntax is definitely correct.
FWIW, while the real time dashboard is a great way to see your hits come in, it should not be considered proof or evidence that something is or isn't working. Everything you send to Google Analytics goes through processing after it comes in, and (for a variety of reasons) a hit may be dropped from reports after showing up successfully in the real time view.
There's also always the possibility that there's a bug in the real time dashboard, and a particular hit may not show up even though it will ultimately make it into your Google Analytics reports.
A much more reliable way to see if your code is working is to take a look at the data that is actually being sent from your page. You can do this via the network inspector (in Chrome) or by using the debug version of analytics.js, which logs status and error message to the console.

Ember.js and Google Analytics

I wanted to get a definitive answer on here for later reference now that we have a stable Ember RC. A combination of the top 2 search results for emberjs google analytics reveals that this is a good way to do track route changes:
App.ApplicationController = Ember.Controller.extend
routeChanged: ( ->
return unless window._gaq
Em.run.next ->
page = if window.location.hash.length > 0 then window.location.hash.substring(1) else window.location.pathname
_gaq.push(['_trackPage', page])
).observes('currentPath')
but then I also see results for using Event Tracking for single page web applications.
I haven't tested the code above yet, it takes a few hours to propagate changes to the GA dashboard. Update: This doesn't show up under the Content category on my Google Analytics dashboard. Neither under "Pages" or "Events".
If anyone has advice or if there's something I'm missing somewhere let me know. I can also PR a guide for the website based on the answers here.
Alex DiLiberto gave a really nice talk about a robust & scalable way of adding Google Analytics to an ember app in his EmberConf 2014 talk here.
- Slides
- GitHub
App.ApplicationRoute = Ember.Route.extend({
actions: {
didTransition: function() {
Ember.run.once(this, function() {
ga('send', 'pageview', this.router.get('url'));
});
}
}
});
The talk was aiming to be independent of which analytics library was used.
There is also now an official Ember Cookbook on implementing Google Analytics here.
I would use _trackPageview for things that have routable URLs and _trackEvent for things that don't.
In the Event Tracking link when they refer to "Embedded AJAX page elements". They're not meaning SPA's, but rather those cases when the URL stays the same, but some event that you wish to track happens within the page (in the case via AJAX).
There may be other cases where it makes sense to use _trackEvent, but for route transitions I'd use _trackPageview.
Using routeChanged() is not a good way to track dynamic segments such as /category/food /category/something since it's going to be fired only once. I wrote an article about this here: http://www.randomshouting.com/2013/05/04/Ember-and-Google-Analytics.html. I also consulted with the guys behind Ember and confirmed that this is indeed the proper way to track url changes for Google Analytics.
Most of these answers are outdated. You should be using a mixin and adding it to your Router to listen for the didTransition event and fire your pageview there. That way it's handled for all routes. There are several addons out there, including one I wrote called ember tracker which gives you pageviews and event tracking out-of-the-box.
You can see how I did it here. It's fairly straight forward.

Analytics receives events, but does not log them in reporting

I've been all over google and SO looking for answers here. I've checked code against google's tracking code suggestions and I've even tested with their sample code. But I cannot get the events to be properly tracked in Google Analytics. My code has been live on the site for some time (~ a month), so this should have overcome any lag on the reports there.
I'm using analytics, the async version, which works fine for page tracking and other 'normal' features. Trying to set up event tracking, I followed the example, and waited a week. Still nothing. I've been debugging and I'm not having any of the 'normal' problems (as far as I can see).
So:
Example tracking code fired:
Play
This triggers an event, which according to ga_debug.js, is fired successfully. Checking the network panel I can see the request and _umt.gif returns status 200.
I've checked the request string in there. All seems good.
But checking GA, there is nothing in the reports. But when you go to GA Realtime > Events, you can see the events being fired!?
I can trigger the events on page or fire them from the console and corresponding events show up in the realtime section, but they have no data (Category, Action or Label).
This is odd, that even firing Google's own example code nothing is showing up.
If anyone has any ideas of where to start debugging for this (or has experience of anything similar), it would be great to hear.
I have been struggling with this issue for three days. I know this thread is old, but I stumbled upon it during my searching. I wanted to post what my personal resolution was in case someone else comes across this.
My Solution:
Here is where I finally found it:
https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables
Under: "Using Custom Variables" > "Traditional (ga.js) Snippet" (We are using the ga.js still... for now.)
I had a similar problem and ran into this issue:
https://issuetracker.google.com/issues/35353093
In summary, I was setting the userId property via below. Removing that started historical tracking for me.
ga('set', 'userId', username);
This question gets asked a lot and the answer is almost always "Google Analytics standard SLA is 24 hours". The logs are processed in batch behind the scenes. At peak times, this takes a while.
It can take up to 24 hours for the Google Analytics servers to update -- Source: Google Documentation - Check your web tracking code setup

Resources