Skip to content

Commit

Permalink
1.0.6
Browse files Browse the repository at this point in the history
* option namespacing
  • Loading branch information
Ryan Brewster committed Oct 30, 2014
1 parent 3672323 commit f3ba99d
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 73 deletions.
12 changes: 7 additions & 5 deletions lib/atrackt.console.js

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

4 changes: 4 additions & 0 deletions lib/atrackt.js

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

33 changes: 17 additions & 16 deletions lib/plugins/atrackt.omniture.js

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

72 changes: 64 additions & 8 deletions spec/atrackt_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ describe 'Atrackt', ->
context 'when tracking an element', ->
before ->
$fooEl = $('<a data-atrackt-category="Anchor" data-atrackt-value="Foo"></a>')
$fooEl.data 'atrackt-function', (data, options) ->
data['function_data'] = true
options['function_option'] = true

Atrackt.plugins['foo-plugin'].track $fooEl,
track_option: true
Expand All @@ -227,22 +224,40 @@ describe 'Atrackt', ->
global_data: true
plugin_data: true
option_data: true
function_data: true
,
global_option: true
plugin_option: true
track_option: true
function_option: true

context 'when tracking by event', ->
before ->
$fooEl = $('<a data-atrackt-category="Anchor" data-atrackt-value="Foo"></a>')
$('body').append $fooEl

Atrackt.plugins['foo-plugin'].setEvent
click: $fooEl

$fooEl.trigger 'click'

it 'should call the send method on plugins with data and options', ->
expect(pluginSpy).to.be.calledWithExactly
_location: 'Atrackt Test'
_categories: ['Anchor']
_value: 'Foo'
_event: 'click'
global_data: true
plugin_data: true
,
global_option: true
plugin_option: true

context 'when tracking an element with a custom function', ->
before ->
$fooEl = $('<a data-atrackt-value="Foo"></a>')
$fooEl.data 'atrackt-function', (data, options) ->
data['function_data'] = true
options['function_option'] = true

$('body').append $fooEl

Atrackt.plugins['foo-plugin'].setEvent
click: $fooEl

Expand All @@ -251,7 +266,7 @@ describe 'Atrackt', ->
it 'should call the send method on plugins with data and options', ->
expect(pluginSpy).to.be.calledWithExactly
_location: 'Atrackt Test'
_categories: ['Anchor']
_categories: []
_value: 'Foo'
_event: 'click'
global_data: true
Expand All @@ -261,3 +276,44 @@ describe 'Atrackt', ->
global_option: true
plugin_option: true
function_option: true

context 'when passing options globally', ->
before ->
$fooEl = $('<a data-atrackt-value="Foo"></a>')

Atrackt.track $fooEl,
global_option: 'global'
global_only: true
'foo-plugin':
plugin_option: 'track-global-plugin-option'
global_option: 'track-global-plugin-overwrite-option'

it 'should', ->
expect(pluginSpy).to.be.calledWithExactly
_location: 'Atrackt Test'
_categories: []
_value: 'Foo'
global_data: true
plugin_data: true
,
global_only: true
global_option: 'track-global-plugin-overwrite-option'
plugin_option: 'track-global-plugin-option'

context 'when passing options on a plugin', ->
before ->
$fooEl = $('<a data-atrackt-value="Foo"></a>')

Atrackt.plugins['foo-plugin'].track $fooEl,
plugin_option: 'track|plugin-option'

it 'should', ->
expect(pluginSpy).to.be.calledWithExactly
_location: 'Atrackt Test'
_categories: []
_value: 'Foo'
global_data: true
plugin_data: true
,
global_option: true
plugin_option: 'track|plugin-option'
47 changes: 25 additions & 22 deletions spec/plugins/atrackt.omniture_spec.coffee
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
describe 'Plugin: Omniture', ->
_plugin = Atrackt.plugins['omniture']

describe '#buildSObject', ->
before ->
window.s = {}
_plugin.options.version = 14
_plugin.options.linkTrackVars = ['foo']
_plugin.buildSObject
bar: 'bar'

it 'should add to the s object', ->
expect(s.foo).to_exist

it 'shoule set linkTrackVars', ->
expect(s.linkTrackVars).to.equal 'foo,bar'
before ->
window.s = {}

describe '#send', ->
obj = null
Expand All @@ -34,15 +23,21 @@ describe 'Plugin: Omniture', ->
it 'should keep the original key if it does not exist in the propMap', ->
expect(obj.bar).to.exist

describe '#keyLookup', ->
describe '#_buildSObject', ->
before ->
_plugin.options.propMap =
foo: 'bar'
window.s = {}
_plugin.options.version = 14
_plugin.options.linkTrackVars = ['foo']
_plugin._buildSObject
bar: 'bar'

it 'should lookup from propMap', ->
expect(_plugin.keyLookup('foo')).to.equal 'bar'
it 'should add to the s object', ->
expect(s.foo).to_exist

it 'shoule set linkTrackVars', ->
expect(s.linkTrackVars).to.equal 'foo,bar'

describe '#buildLinkName', ->
describe '#_buildLinkName', ->
linkName = null

before ->
Expand All @@ -53,22 +48,30 @@ describe 'Plugin: Omniture', ->
_location: 'prop2'
_categories: 'prop3'

linkName = _plugin.buildLinkName
linkName = _plugin._buildLinkName
prop1: 'baz'
prop2: 'foo'
prop3: 'bar'

it 'should build a link name', ->
expect(linkName).to.equal 'foo|bar|baz'

describe '#translatePropMap', ->
describe '#_translatePropMap', ->
pre = null
post = null

before ->
pre =
integer: 10
post = _plugin.translatePropMap pre
post = _plugin._translatePropMap pre

it 'should handle any value type', ->
expect(post['integer']).to.equal '10'

describe '#_keyLookup', ->
before ->
_plugin.options.propMap =
foo: 'bar'

it 'should lookup from propMap', ->
expect(_plugin._keyLookup('foo')).to.equal 'bar'
3 changes: 3 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### CHANGE LOG
###### 1.0.6
* option namespacing

###### 1.0.5
* console scroll fix
* console sets existing plugins on load
Expand Down
4 changes: 4 additions & 0 deletions src/atrackt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ https://github.com/brewster1134/atrackt

# Loop through each plugin and check if the data should be tracked
for pluginName, pluginData of @plugins
# extract plugin specific data
if options[pluginName]
$.extend true, options, options[pluginName]
delete options[pluginName]

# If tracking is triggered by an event, make sure the event namespace matches the plugin or is global
if event
Expand Down
17 changes: 9 additions & 8 deletions src/atrackt.console.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ https://github.com/brewster1134/atrackt
###

((root, factory) ->
if location.href.indexOf('atracktConsole') > -1
if typeof define == 'function' && define.amd
define [
'jquery'
'atrackt'
'jquery.scrollTo'
], ($, Atrackt) ->
if typeof define == 'function' && define.amd
define [
'jquery'
'atrackt'
'jquery.scrollTo'
], ($, Atrackt) ->
if location.href.indexOf('atracktConsole') > -1
$ ->
window.Atrackt = new(factory($, Atrackt.constructor))
else
else
if location.href.indexOf('atracktConsole') > -1
window.Atrackt = new(factory(window.jQuery, window.Atrackt.constructor))
) @, ($, Atrackt) ->

Expand Down
32 changes: 18 additions & 14 deletions src/plugins/atrackt.omniture.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,31 @@ https://github.com/brewster1134/atrackt
) @, ($, Atrackt) ->

window.Atrackt.setPlugin 'omniture',

# default options
options:
trackingType: 'o'
charReplaceRegex: /[^\x20-\x7E]/g
version: 14
delimiters:
linkName: '/'
category: '|'
linkTrackVars: ['products', 'events']
propMap:
_location : 'prop1'
_categories : 'prop2'
_value : 'prop3'
_event : 'prop4'

send: (data, options) ->
return console.error 'ATRACKT ERROR: PLUGIN `omniture` - Site catalyst library not loaded' if typeof s == 'undefined'
console.log 'dataoptions', data, options

$.extend true, @options, options
data._categories = data._categories?.join @options.delimiters.category
data = @_translatePropMap data


@_buildSObject data
if @options.page && s.t?
s.t()
Expand All @@ -35,20 +53,6 @@ https://github.com/brewster1134/atrackt
s.tl arg, @options['trackingType'], @_buildLinkName data
data

options:
trackingType: 'o'
charReplaceRegex: /[^\x20-\x7E]/g
version: 14
delimiters:
linkName: '/'
category: '|'
linkTrackVars: ['products', 'events']
propMap:
_location : 'prop1'
_categories : 'prop2'
_value : 'prop3'
_event : 'prop4'

# omniture specific
_buildSObject: (obj) ->
switch @options.version
Expand Down

0 comments on commit f3ba99d

Please sign in to comment.