Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

extract Analytics boostrap code & track user interaction events

  • Loading branch information...
commit 5591ad63e74e27e48c2830695bf860082cd3f5ab 1 parent 7e5c7e0
@mislav authored
View
39 endless_tweets/endless_tweets.js
@@ -33,42 +33,15 @@ var $et = {
version: '0.9.9',
scriptSize: 0,
- pageTracker: realWindow._gat && realWindow._gat._getTracker("UA-87067-6"),
- segmentUser: function(seg) {
- if (this.pageTracker) {
- try { this.pageTracker._setVar(seg) } catch(err) {}
- }
- },
- trackPageview: function(path) {
- if (this.pageTracker) {
- if (path) {
- var url = (path instanceof URL) ? path : new URL(path)
- path = url.pathWithQuery()
- if (url.domain && url.domain != 'twitter.com') path = '/' + url.domain + '/' + path
- }
- try { this.pageTracker._trackPageview(path) } catch(err) {}
- }
- },
- trackClicks: function(element, fn) {
- element.addEventListener('mousedown', function(e) {
- if (e.button == 0) {
- var url = null
- if (typeof fn == "function") url = fn.call(this, e)
- else if (fn) url = fn
- else if (element.href) url = element.href
-
- if (url) this.trackPageview(url)
- }
- }, false)
- },
-
getSessionCookie: function() {
return (document.cookie.toString().match(/_twitter_sess=[^\s;]+/) || [])[0]
}
}
+//= toolkit/analytics.js
+applyAnalytics($et, realWindow._gat, "UA-87067-6")
+
$et.inspectPage()
-$et.trackPageview()
// have "from Endless Tweets" appear when users post updates
var statusUpdateSource = find($et.updateForm, '#source')
@@ -222,7 +195,7 @@ if (content) {
reveal(update)
twttr.loaded()
livequeryRun()
- $et.trackPageview(statusUrl)
+ $et.trackEvent('timeline', 'in_reply_to', 'loaded status ' + statusID)
})
}, { onerror: fallback })
e.preventDefault()
@@ -245,13 +218,13 @@ function checkViewportWidth() {
if (!miniMode) {
addClassName(document.body, 'mini')
miniMode = true
- $et.segmentUser('mini layout')
+ $et.trackEvent('layout', 'mini')
}
}
else if (miniMode) {
removeClassName(document.body, 'mini')
miniMode = false
- $et.segmentUser('')
+ $et.trackEvent('layout', 'restore')
}
}
window.addEventListener('resize', checkViewportWidth, false)
View
2  endless_tweets/inline_reply.js
@@ -47,6 +47,7 @@ if (replyLink) {
}
insertAfter(miniTimeline, $('permalink'))
reveal(miniTimeline.firstChild)
+ $et.trackEvent('timeline', 'inline_reply', 'replied to ' + username)
}, {
method: replyForm.getAttribute('method'),
data: {
@@ -63,6 +64,7 @@ if (replyLink) {
e.preventDefault()
replyLink.removeEventListener('click', replyHandler, false)
+ $et.trackEvent('timeline', 'inline_reply_form', 'replying to ' + username)
}
replyLink.addEventListener('click', replyHandler, false)
}
View
1  endless_tweets/polling.js
@@ -57,6 +57,7 @@ function checkUpdates() {
if (count) {
$et.setLastRead(data.id)
livequeryRun()
+ $et.trackEvent('timeline', 'polling', 'found updates for ' + $et.currentUser, count)
}
})
}
View
39 toolkit/analytics.js
@@ -0,0 +1,39 @@
+function applyAnalytics($, gat, account) {
+ var pageTracker = gat && gat._getTracker(account)
+
+ if (pageTracker) {
+ pageTracker._setDetectFlash(false)
+ } else {
+ $.segmentUser = $.trackPageview = $.trackEvent = $.trackClicks = function(){}
+ return
+ }
+
+ $.segmentUser = function(seg) {
+ try { pageTracker._setVar(seg) } catch(err) {}
+ }
+ $.trackPageview = function(path) {
+ if (path) {
+ var url = (path instanceof URL) ? path : new URL(path)
+ path = url.pathWithQuery()
+ if (url.domain && url.domain != 'twitter.com') path = '/' + url.domain + '/' + path
+ }
+ try { pageTracker._trackPageview(path) } catch(err) {}
+ }
+ $.trackEvent = function(category, action, label, value) {
+ try { pageTracker._trackEvent(category, action, label, value) } catch(err) {}
+ }
+ $.trackClicks = function(element, fn) {
+ element.addEventListener('mousedown', function(e) {
+ if (e.button == 0) {
+ var url = null
+ if (typeof fn == "function") url = fn.call(this, e)
+ else if (fn) url = fn
+ else if (element.href) url = element.href
+
+ if (url) this.trackPageview(url)
+ }
+ }, false)
+ }
+
+ $.trackPageview()
+}
Please sign in to comment.
Something went wrong with that request. Please try again.