Skip to content

Instantly share code, notes, and snippets.

@ju1
Last active January 21, 2020 00:15
Show Gist options
  • Save ju1/5174765b29604a57fe20314378ca1f32 to your computer and use it in GitHub Desktop.
Save ju1/5174765b29604a57fe20314378ca1f32 to your computer and use it in GitHub Desktop.
<script>
if (typeof twttr !== 'undefined') {
twttr.ready(function (twttr) {
twttr.events.bind('tweet', tweetIntentToAnalytics);
twttr.events.bind('retweet', retweetIntentToAnalytics);
twttr.events.bind('favorite', favIntentToAnalytics);
twttr.events.bind('follow', followIntentToAnalytics);
});
}
function clickEventToAnalytics() {
dataLayer.push({
'event': 'socialInteraction',
'socialNetwork': 'Twitter',
'socialAction': 'click',
'socialTarget': window.location.href
});
}
function tweetIntentToAnalytics() {
dataLayer.push({
'event': 'socialInteraction',
'socialNetwork': 'Twitter',
'socialAction': 'tweet',
'socialTarget': window.location.href
});
}
function retweetIntentToAnalytics() {
dataLayer.push({
'event': 'socialInteraction',
'socialNetwork': 'Twitter',
'socialAction': 'retweet',
'socialTarget': window.location.href
});
}
function favIntentToAnalytics() {
dataLayer.push({
'event': 'socialInteraction',
'socialNetwork': 'Twitter',
'socialAction': 'favorite',
'socialTarget': window.location.href
});
}
function followIntentToAnalytics() {
dataLayer.push({
'event': 'socialInteraction',
'socialNetwork': 'Twitter',
'socialAction': 'follow',
'socialTarget': window.location.href
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment