Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics code in plugin

I am developing jquery plugin, I want to incorporate Google Analytics inside it and want to track events on my plugin.

Confusion is will it report to both, my Google Analytics Stats and Website(website which integrated my plugin) ?

like image 234
Abdul Rauf Avatar asked Nov 02 '22 01:11

Abdul Rauf


1 Answers

3 Things to be aware of when doing this:

  1. Be sure to tell your users or give them a way to opt-out if you are distributing this plugin. I can't say I've seen many jQuery plugins that have tracking included (for obvious reasons).

  2. Use a different GA property than what you're using for your website.

  3. Use tracker namespacing.

For analytics.js:

ga('create', 'UA-123456-7', 'auto', {'name': 'myPluginName'}); 
ga('myPluginName.send', 'pageview');

Or for ga.js:

_gaq.push(['myPluginName._setAccount', 'UA-123456-7']);
_gaq.push(['myPluginName._trackPageview']);

For more details visit Google Analytics site: https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gaq

like image 71
MisterPhilip Avatar answered Nov 09 '22 09:11

MisterPhilip