Usually, you can just set different tracking codes with different recording ratios on the various pages of your website. But when using content management systems like Joomla or WordPress, the code appears on all pages identically. Other case might also require parsing the URL in order to ascertain the appropriate recording ratio. Here is an example of a code which does this:
Instead of your regular bottom part, place this:
Code:
<!-- ClickTale Bottom part -->
<div id="ClickTaleDiv" style="display: none;"></div>
<script src="http://s.clicktale.net/WRb.js" type="text/javascript"></script>
<script type="text/javascript">
function escapeRegex(text) {
if (!arguments.callee.sRE) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
arguments.callee.sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
}
return text.replace(arguments.callee.sRE, '\\$1');
}
function urlPathIs(urls) {
/// <summary>Check if the current url matches any of the given urls passed</summary>
/// <param name="urls" type="Array[String]|String">A url or an array of urls to test against</param>
/// <returns type="Boolean">True if the the current location matches any of the passed urls, false otherwise</returns>
if(arguments.length > 1) {
urls = Array.prototype.slice.call(arguments, 0);
}
if(typeof urls == "string") {
urls = [urls];
}
var escapedUrls = [],
regexp;
for(var i = 0; i < urls.length; i++) {
escapedUrls.push(escapeRegex(urls[i]));
}
regexp = new RegExp("^(?:"+escapedUrls.join("|")+")/?(?:\\?|$|#)","i");
return regexp.test(window.location.href);
}
The next stage is to continue the bottom part with if/else statements (or a switch statement) which determines the recording ratio according to the current URL. This next bit is an example of a user who wants to record 100% of visitors to his homepage and his contact page, and non of the visitors to other pages. You can also set other value to the recording ratio (see
http://forum.clicktale.net/viewtopic.php?f=2&t=548 for more details).
Code:
var recordingratio = 0;
if (urlPathIs ("http://domain.com","http://www.domain.com","http://domain.com/contact","http://www.domain.com/contact")) {
recordingratio = 1;
}
Finally, once the ratio is determined, you can place it in the recording function as it appears on your original tracking code (in this case it's for a regular page, https pages and other special cases require a different code but the concept is the same):
Code:
if(typeof ClickTale=='function' && recordingratio>0) ClickTale([!YOUR PROJECT ID!],recordingratio,[!PARTITION!]);
</script>
<!-- ClickTale end of Bottom part -->
You can also set the ratio by other values, such as the referrer (document.referrer property).