Created
February 12, 2018 07:31
-
-
Save simenbrekken/fc8b59219f58fe7191f1656213f08960 to your computer and use it in GitHub Desktop.
KISS analytics abstraction
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
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