Skip to content
WJunction - Webmaster Forum

Google Analytics: Multiple accounts with jQuery

Status
Not open for further replies.
Ok what this tutorial will show you is how to set up 2 google analytics trackers on one site.. this is good if you have sub owners of your sites..


For litewarez theres me and the other admin where we have our own tracking settings.

The first thing you need to make sure is that you have jQuery included in your pages!

And heres is the function

Code:
GATracker = {
	Start : function(){
		this.LoadGoogle();
	},
	LoadGoogle : function(){
		var http_ = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.")
		$.getScript(http_ + "google-analytics.com/ga.js",function(){
			/*Here the main js source for google is loaded we can start for each account*/
			var admin_one = _gat._getTracker("UA-XXXXXXXX-X");
			var admin_two = _gat._getTracker("UA-XXXXXXXX-X");
			
			/*Ok so now we have to varaibles that you can do some stuff with...*/
			/*Both trackers are running now and google should recived data*/
			
			/*
				This is a little nifty trick you can do to percifically
				track outbound links, katz do this aswell. but you dont have to
			*/
			$('a[href^=http]:not("[href*=://' + document.domain + ']")').click(function() {
				admin_one ._trackPageview('/external/' + $(this).attr("href"));
				admin_two ._trackPageview('/external/' + $(this).attr("href"));
			}
		});
	}
}

/*And anywhere in your javascript you can load the tracker like so*/

$(document).ready(function(){GATracker.Start();});

Now as you can see the above code should be tracking out bound links and working with 2 seperate accounts!

54ae5cf3a0.png



Hope you enjoy
 

7 comments

because

No1. Your google password is your password fro everything really Youtube,Webmasters,Gmail,

Not that the other admin is untrusted if they run other sites aswell they dont ahve to go into multiple accounts to view stats
 
Just so you know the loading of google analystics is known to cost up to a second on pageloads, if trying to optimise loading times be carefull.
 
wow SplitIce. That's a lot, didn't know that.

Anyway why don't you just add the person in Google Analytics? They don't need to know your password etc this way. I don't understand the advantage in two Google Analytics Accounts. Am I missing something?
See the images below on how to allow another person to view the stats.

2qa7kag.jpg


mkahw0.jpg
 
because

No1. Your google password is your password fro everything really Youtube,Webmasters,Gmail,

Not that the other admin is untrusted if they run other sites aswell they dont ahve to go into multiple accounts to view stats

You can add other google accounts to a specific domain, like Sickness and I do with our sites.

Exactly what Mr Happy said.
 
Status
Not open for further replies.

About the author

L
Active Member · Joined
I am a skilled programmer within PHP,HTML,CSS,MYSQL and also the owner of several websites Programming, Football...
1,367
Messages
1
Reactions
38
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom