// Create global _gaq if needed var _gaq = _gaq || []; // Create global amcAnalytics as wrapper amcAnalytics = new AMCAnalytics(); // Call the page tracking wrapper function amcAnalytics.trackPage(); // Here is the ga code to laod (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); function AMCAnalytics(){ this.production = true; this.asset = "WMGO"; this.ecomm = new Object(); this.gaAccount = "UA-9701869-1"; this.domain = ".outdoors.org"; this.codeOnly = false; this.trackPage = function(pageName) { _gaq.push(['_setAccount', this.gaAccount]); _gaq.push(['_setDomainName', this.domain]); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_setAllowHash', false]); if (pageName) { _gaq.push(['_trackPageview']); } else { _gaq.push(['_trackPageview', pageName]); } //alert("Just called page track for "+this.domain); } /* the next three methods serve as wrapper for the handling e-commerce calls to Google. To initialize a new transaction call AMCAnalytics.ecommNew() with unqiue transaction ID, tax and shipping totals grand total will be automatically calculated by calls to ecommAddItem */ this.ecommNew = function(parentObject) { this.ecomm.tranID = parentObject.tranID; this.ecomm.total = 0; this.ecomm.tax = parentObject.tax; this.ecomm.shipping = parentObject.shipping; this.ecomm.items = new Array(); } /* Call this to add new items to the ecomm transaction */ this.ecommAddItem = function(itemObject) { var x = this.ecomm.items[this.ecomm.items.length] = new Object(); x.sku=itemObject.sku; x.product = itemObject.product; x.category = itemObject.category; x.qty = itemObject.qty; x.price = itemObject.price; this.ecomm.total += x.qty * x.price; } /* Call this to post the transaction to google or other analytics provider*/ this.ecommPost = function() { // Post primary record _gaq.push(['_addTrans', this.ecomm.tranID, // order ID - required 'AMC Lodging', // affiliation or store name this.ecomm.total, // total - required this.ecomm.tax, // tax this.ecomm.shipping // shipping ]); // Loop and post items for (var i = 0; i