Created
December 11, 2014 15:57
-
-
Save vmysla/ffccf789044d2dda18b2 to your computer and use it in GitHub Desktop.
JavaScript for cookie-based Transaction Reporting (GA, Marine)
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
(function(){ | |
var pixels = []; | |
pixels.push(function googleAnalytics(transaction){ | |
ga('ec:setTransactionId', transaction.id); | |
... | |
ga('send', ... ); | |
}); | |
pixels.push(function marin(transaction){ | |
var _mTrack = _mTrack || []; | |
_mTrack.push(...); | |
... | |
}); | |
reportTransactions(); | |
function reportTransactions(){ | |
var cookieName = 'transactions'; | |
var ids = parseCookie(cookieName); | |
_satellite.each(ids, reportTransaction); | |
_satellite.removeCookie(cookieName); | |
} | |
function reportTransaction(id){ | |
var cookieName = 'transaction'+id; | |
var transaction = _satellite.readCookie(id) || null; | |
if(transaction){ | |
_satellite.each(pixels, function firePixel(fn){ fn(transaction); }); | |
_satellite.removeCookie(cookieName); | |
} | |
} | |
function parseCookie(name){ | |
var value = _satellite.readCookie(name); | |
return JSON.parse(value); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment