How To: Split Metrics Between Two Report Suites Using A Single s_code.js File

One thing I like to do is snoop around at others code. Some may say I’m being nosy, I like to think I’m admiring others work. You come across some pretty neat ideas looking at the code of others. With a little creativity you can use others ideas and apply them to something that is beneficial to you. Sometimes you come across a neat chunk of code that you will want to keep as it. This is one of those interesting finds.

Many of the sites I work on are rather large, and have separate domains setup for our dev/testing environment. If you are delivering millions and millions of page views a week, you don’t want to test in a live environment. What we like to do is have out pubic facing site set up as www.mysite.com, and our testing/development site setup with a dev subdomain, dev.mysite.com. The value in this enhancement come where both sites, your public site and development site,have the ability to use the same s_code.js file without mixing the metrics in the UI.

Let’s say your site is www.mysite.com and your testing site is dev.mysite.com. In the top on your s_code.js file, add a function before any other code.

function switchSuite() {
	var suiteList= "";

	if (location.hostname.indexOf('dev')!=-1) {
		suiteList += "DEV_SUITE_NAME";
		} else {
		suiteList += "MAIN_SUITE_NAME";
		}
	return suiteList
	}

When the main code begins, insert the function call in the s_account spot.

var s_account=switchSuite()

On the sites I work with, we actually have many different testing, development and staging subdomains that I want to keep separate, so I can use a few domains listed in that first position.

	if (location.hostname.indexOf('dev')!=-1 || location.hostname.indexOf('qa')!=-1 || location.hostname.indexOf('staging')!=-1) {
		suiteList += "DEV_SUITE_NAME";
	} else {
		suiteList += "MAIN_SUITE_NAME";
	}
	return suiteList
}

This will now look at the subdomain and fill in the correct account name. You may just say ‘hey, just remove the analytics from the testing page’, but I like to keep that on there to make sure any enhancements to the site do not have any effect on the analytics.

Another neat use of this is if you have multiple subdomains of unrelated content that you have individual report suites set up for. Take a look at Yahoo. They have tons of micro-sites, all subdomain based that I would want to count individually of one another. I may not want all the data from autos.yahoo.com swimming around with realestate.com so this is a great use this code as well. Hopefully you will be able to find some interesting uses for it.

Leave a Reply