Created
April 19, 2013 16:47
-
-
Save wfendler/5421580 to your computer and use it in GitHub Desktop.
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
class TrackAnalytics | |
constructor: (@el) -> | |
@bindEvents() | |
bindEvents: -> | |
$('body').on 'click', '.track', (e) => | |
e.preventDefault() | |
@setEventProps() | |
@._gaqBuilder(@eventProperties) | |
if @doublePush | |
@._gaqBuilder(@eventProperties2) | |
setEventProps: -> | |
@doublePush = true if $.isArray(eventSource) | |
formTracker = true if @el.hasClass('track-form') | |
campaign = @el.data('campaign') | |
# Set value dynamically for tracked forms | |
if formTracker | |
inputVal = @el.prev('.track-input').val() | |
if !inputVal | |
inputVal = 'empty_search' | |
eventSource = @el.data('eventsource') + inputVal | |
else | |
eventSource = @el.data('eventsource') | |
console.log eventSource | |
# Set both eventProperties for doublePush items | |
if @doublePush | |
eventProperties = | |
type: '_trackEvent' | |
campaign: campaign[0] | |
page: CAMBRIA.pageName | |
source: eventSource[0] | |
eventProperties2 = | |
type: '_trackEvent' | |
campaign: campaign[1] | |
page: CAMBRIA.pageName | |
source: eventSource[1] | |
else | |
eventProperties = | |
type: "_trackEvent" | |
campaign: campaign | |
page: CAMBRIA.pageName | |
source: eventSource | |
@eventProperties = eventProperties | |
_gaqBuilder: (prop) -> | |
if _gaq? | |
return _gaq.push([prop.type, prop.campaign, prop.page, prop.source]) | |
$ -> | |
$('.track').each -> | |
el = $(@) | |
new TrackAnalytics(el) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment