var form_analytics = {}; //namespace
form_analytics.DetectBrowser = {
init: function ()
{
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
},
searchString: function (data)
{
for (var i = 0; i < data.length; i++)
{
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString)
{
if (dataString.indexOf(data[i].subString) != -1) return data[i].identity;
}
else if (dataProp) return data[i].identity;
}
},
searchVersion: function (dataString)
{
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Chrome",
identity: "Chrome"
}, {
string: navigator.userAgent,
subString: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
}, {
string: navigator.vendor,
subString: "Apple",
identity: "Safari",
versionSearch: "Version"
}, {
prop: window.opera,
identity: "Opera"
}, {
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
}, {
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
}, {
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
}, {
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
}, { // for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
}, {
string: navigator.userAgent,
subString: "MSIE",
identity: "Internet Explorer",
versionSearch: "MSIE"
}, {
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
}, { // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}]
};
form_analytics.DetectBrowser.init();
if (typeof (_gat) != "undefined")
{
form_analytics.pageTracker = _gat._getTracker("UA-1-1");
form_analytics.pageTracker._trackPageview();
}
form_analytics._uGC = function (l, n, s)
{
if (!l || l == "" || !n || n == "" || !s || s == "") return "-";
var i, i2, i3, c = "-";
i = l.indexOf(n);
i3 = n.indexOf("=") + 1;
if (i > -1)
{
i2 = l.indexOf(s, i);
if (i2 < 0)
{
i2 = l.length;
}
c = l.substring((i + i3), i2);
}
return c;
}
form_analytics.addDataToForm = function( form ) {
// form is a jQuery object
form = jQuery(form);
form.find('input[name^="igz_"]').remove();
//now, create a data element for us
var formbody = form.find('.gform_body');
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
var z = form_analytics._uGC(document.cookie, '__utmz=', ';');
var content = form_analytics._uGC(z, 'utmcct=', '|');
var campaign = form_analytics._uGC(z, 'utmccn=', '|');
var keyword = form_analytics._uGC(z, 'utmctr=', '|');
var gclid = form_analytics._uGC(z, 'utmgclid=', '|');
var source = form_analytics._uGC(z, 'utmcsr=', '|');
var term = form_analytics._uGC(z, 'utmctr=', '|');
var medium = form_analytics._uGC(z, 'utmcmd=', '|');
if (gclid != "-")
{
source = 'google';
medium = 'cpc';
}
var csegment = form_analytics._uGC(document.cookie, '__utmv=', ';');
if (csegment != '-')
{
var csegmentex = /[1-9]*?\.(.*)/;
csegment = csegment.match(csegmentex);
csegment = csegment[1];
}
else
{
csegment = '(not set)';
}
// Visits
var a = form_analytics._uGC(document.cookie, '__utma=', ';');
var aParts = a.split(".");
var nVisits = aParts[5];
// Term & pageviews
var a = form_analytics._uGC(document.cookie, '__utmb=', ';');
var aParts = a.split(".");
var pViews = aParts[1];
term = term.split('%20');
var no = term.length;
aa = '';
for (var i = 0; i < no; i++)
{
aa = aa + ' ' + term[i];
}
term = aa;
if( pViews == undefined ) {
pViews = '';
}
// grab cookie data from other script
var cookie = JSON.parse(getCookie("traffic_source"));
//console.debug(cookie);
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
formbody.append("");
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i" + "");
jQuery(document).bind('gform_page_loaded', function(event, form_id, current_page){
var form = $('#gform_wrapper_' + form_id);
console.log('refreshing data for form '+form_id);
form_analytics.addDataToForm(form);
});
$('.gform_wrapper').each(function() {
// call the fn to create & fill in our data.
form_analytics.addDataToForm(this);
});
});