Skip to content

@kressaty /ga-twitter.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Twitter Button Google Analytics
// This assumes that you have included the Tweet button via the standard Twitter JS include
// Thanks to Google for most of this code, see the Social Interaction Analytics guide at
// https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial
// To track a Tweet, subscribe to the tweet event (note the additional function required
// to determine the query parameter being sent to Twitter):
function trackTwitter(intent_event) {
if (intent_event) {
var opt_pagePath;
if (intent_event.target && intent_event.target.nodeName == 'IFRAME') {
opt_target = extractParamFromUri(intent_event.target.src, 'url');
}
_gaq.push(['_trackSocial', 'twitter', 'tweet', opt_pagePath]);
}
}
twttr.ready(function (twttr) {
twttr.events.bind('tweet', trackTwitter);
});
function extractParamFromUri(uri, paramName) {
if (!uri) {
return;
}
var regex = new RegExp('[\\?&#]' + paramName + '=([^&#]*)');
var params = regex.exec(uri);
if (params != null) {
return unescape(params[1]);
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.