Skip to content

Commit

Permalink
and headers for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Brewster committed Oct 28, 2014
1 parent 846a13a commit 8565583
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 193 deletions.
66 changes: 38 additions & 28 deletions lib/plugins/atrackt.localytics.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 85 additions & 75 deletions lib/plugins/atrackt.omniture.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 42 additions & 33 deletions src/plugins/atrackt.localytics.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,45 @@ https://github.com/brewster1134/atrackt
@version 1.0.0
###

window.Atrackt.setPlugin 'localytics',
send: (data, options) ->
if @_isUiWebView()
redirectUrl = @_getRedirectUrl data, options
@_redirect redirectUrl
else
@_callTagMethod data, options

# HTML5 methods
#
_callTagMethod: (data, options) ->
localyticsSession?.tagEvent options.eventName, data

# UIWebView/HTML5 Hybrid methods
#

# Check if being run in UIWebView
#
_isUiWebView: ->
/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent)

_getRedirectUrl: (data, options) ->
redirectUrl = if options.screenEvent
"localytics://?screenEvent=#{options.eventName}"
else
"localytics://?event=#{options.eventName}"


redirectUrl += "&attributes=#{JSON.stringify(data)}" if Object.keys(data).length
redirectUrl

_redirect: (url) ->
window.location = url if @_isUiWebView()
((root, factory) ->
if typeof define == 'function' && define.amd
define [
'atrackt'
], (Atrackt) ->
factory Atrackt
else
factory Atrackt
) @, (Atrackt) ->

window.Atrackt.setPlugin 'localytics',
send: (data, options) ->
if @_isUiWebView()
redirectUrl = @_getRedirectUrl data, options
@_redirect redirectUrl
else
@_callTagMethod data, options

# HTML5 methods
#
_callTagMethod: (data, options) ->
localyticsSession?.tagEvent options.eventName, data

# UIWebView/HTML5 Hybrid methods
#

# Check if being run in UIWebView
#
_isUiWebView: ->
/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent)

_getRedirectUrl: (data, options) ->
redirectUrl = if options.screenEvent
"localytics://?screenEvent=#{options.eventName}"
else
"localytics://?event=#{options.eventName}"

redirectUrl += "&attributes=#{JSON.stringify(data)}" if Object.keys(data).length
redirectUrl

_redirect: (url) ->
window.location = url if @_isUiWebView()
Loading

0 comments on commit 8565583

Please sign in to comment.