Skip to content

Instantly share code, notes, and snippets.

@simenbrekken
Created February 12, 2018 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simenbrekken/fc8b59219f58fe7191f1656213f08960 to your computer and use it in GitHub Desktop.
Save simenbrekken/fc8b59219f58fe7191f1656213f08960 to your computer and use it in GitHub Desktop.
KISS analytics abstraction
const googleAnalytics = event => {
switch (event.type) {
default:
window.dataLayer.push(event)
}
}
const facebook = event => {
switch (event.type) {
case 'pageview':
fbq('track', 'PageView')
case 'completeCheckout':
fbq('track', 'Purchase', {
currency: event.currency
})
}
}
const integrations = [googleAnalytics, facebook]
export const track = event => {
if (event) {
integrations.forEach(integration => integration(event))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment