Anthony Raimondo
Anthony Raimondo

Reputation: 1721

Google Analytics tracking events causing server problems

I have a widget that loads a iframe of our site, the widget is loaded on over 100 unique websites, the iframe is pointing to a page on our site that hosts the widget it also loads google analytics tracking code and 1-3 events are fired.

My issue is that our server receives super high cpu usage because of the fired events. I tested this by removing the events and the cpu usage goes down to 1-2%. What I don't understand is why the server is impacted at all?

My thoughts are that Javascript is client side, the event fires and a http request is sent to google analytics servers from the client? At least that's what I think is happening. Why would our server be so heavily impacted to the point of 100% cpu usage and crashing for a client side ga event?

Note: The code is loaded asynchronously.

This is the standard tracking code I'm using: analytics.js:

(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-XXXXXXXX-2', 'auto');

ga('send', 'event', 'widget', 'view', 'post',{
    dimension2 : 8,
    dimension3 : 110,
    dimension7 : 1,
    dimension5 : 1,
    dimension6 : 'somee text here'
}
);

Plus maybe 2 more events that look like this one.

New Info Edit:

The spike only happens after the widget is fully loaded and all the javascript is generated. This is the case because the widget has events that fire on click. The cpu usage is stable for loading the boiler plate ga code. But when the event is fired on click our server spikes.

Upvotes: 1

Views: 309

Answers (1)

Anthony Raimondo
Anthony Raimondo

Reputation: 1721

Ok it seems i resolved the problem in 2 ways.

The first is before an event fires you must ALWAYS run:

ga('send', 'pageview');

This error was found as a red warning in my google analytics dashboard.

The second is google analytics expects only string for events so the new event code should look like this.

//All numbers replaced with strings
ga('send', 'event', 'widget', 'view', 'post',{
    'dimension2' : '8',
    'dimension3' : '110',
    'dimension7' : '1',
    'dimension5' : '1',
    'dimension6' : 'somee text here'
});

This error was discovered in my client side console using analytics_debug.js instead of analytics.js when loading boiler plate ga code.

But i still have no idea why my server was so heavily impacted my this. It could be that i accidentally fixed a back end bug while making these changes...

Upvotes: 0

Related Questions