Created
February 28, 2012 18:35
-
-
Save weisjohn/1934196 to your computer and use it in GitHub Desktop.
CoreMetrics Library Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* recordAnalytics( { | |
* 'cm': { | |
* 'pageid': 'your/tag/here', // required | |
* 'searchstring': 'your search string', // optional | |
* 'categoryid': 'your_category_id' // optional | |
* 'type' : 'type of tag' // optional | |
* }, | |
* }); | |
* | |
* @param obj | |
* @return boolean (true if no url) | |
*/ | |
function recordAnalytics(obj) { | |
if ((typeof obj.cm) != 'undefined') { | |
if ((typeof obj.cm.type) == 'undefined' || ( (typeof obj.cm.type) != 'undefined' && obj.cm.type == "pageview" )) { | |
// TODO: what is this window.first_page_id thing? Kill it? | |
if (typeof window.first_page_id == "undefined") { window.first_page_id = obj.cm.pageid; } | |
cmCreatePageviewTag( | |
obj.cm.pageid, | |
((typeof obj.cm.categoryid) != 'undefined') ? obj.cm.categoryid : null, | |
((typeof obj.cm.searchstring) != 'undefined') ? obj.cm.searchstring : null | |
); | |
} else if (obj.cm.type == "conversion") { | |
cmCreateConversionEventTag( | |
obj.cm.pageid, | |
((typeof obj.cm.status) != 'undefined') ? obj.cm.status : null, | |
((typeof obj.cm.categoryid) != 'undefined') ? obj.cm.categoryid : null | |
); | |
} else if (obj.cm.type == "element") { | |
cmCreateElementTag( | |
obj.cm.pageid, | |
((typeof obj.cm.categoryid) != 'undefined') ? obj.cm.categoryid : null, | |
((typeof obj.cm.attributeId) != 'undefined') ? obj.cm.attributeId : null | |
); | |
} else if (obj.cm.type == "manual") { | |
cmCreateManualLinkClickTag( | |
location.href.substring(0, location.href.indexOf('?') != -1 ? location.href.indexOf('?') : location.href.length) + '?' + obj.cm.href, | |
obj.cm.linkname, | |
((typeof obj.cm.pageid) != 'undefined') ? obj.cm.pageid : null | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment