Products
Webtrends Analytics 9.x
Cause
In certain situations, it may be desired or necessary to load a plugin only in certain circumstances.
Resolution
The way to do this is to create the object that includes the plugins manually. Keep in mind that each plugin is also an object. Therefore, it is best to create an object for each plugin even if its always included. The conditional logic then determines which objects are added to the overall plugins object and then the plugins object is included when initializing the Webtrends dcs object.
Below is an example that checks to see if there is a secure connection and if Android 1.x or Android 2.x are being used and if they are, it will not include the heatmaps plugin.
window.webtrendsAsyncInit=function(){
var dcs=new Webtrends.dcs()
var pluginObjs = new Object();
if ((location.protocol.indexOf(‘https:’) == 0 &&(navigator.userAgent.indexOf(“Android 2”) > -1 || navigator.userAgent.indexOf(“Android 1”) > -1))) {
// Do nothing
} else {
pluginObjs.hm = {src:”//s.webtrends.com/js/webtrends.hm.js”};
}
dcs.init({
dcsid:”dcs9u101cvz5bdv0z3m0cixpt_9c5d”,
domain:”statse.webtrendslive.com”,
timezone:-8,
i18n:true,
fpcdom:”.example.com”,
plugins:pluginObjs
}).track();
};
(function(){
var s=document.createElement(“script”); s.async=true; s.src=”/scripts/webtrends/webtrends.js”;
var s2=document.getElementsByTagName(“script”)[0]; s2.parentNode.insertBefore(s,s2);
}());
Below is an example that checks to see if there is a secure connection and if Android 1.x or Android 2.x are being used and if they are, it will not include the heatmaps plugin.
window.webtrendsAsyncInit=function(){
var dcs=new Webtrends.dcs()
var pluginObjs = new Object();
if ((location.protocol.indexOf(‘https:’) == 0 &&(navigator.userAgent.indexOf(“Android 2”) > -1 || navigator.userAgent.indexOf(“Android 1”) > -1))) {
// Do nothing
} else {
pluginObjs.hm = {src:”//s.webtrends.com/js/webtrends.hm.js”};
}
dcs.init({
dcsid:”dcs9u101cvz5bdv0z3m0cixpt_9c5d”,
domain:”statse.webtrendslive.com”,
timezone:-8,
i18n:true,
fpcdom:”.example.com”,
plugins:pluginObjs
}).track();
};
(function(){
var s=document.createElement(“script”); s.async=true; s.src=”/scripts/webtrends/webtrends.js”;
var s2=document.getElementsByTagName(“script”)[0]; s2.parentNode.insertBefore(s,s2);
}());