Skip to content

Commit

Permalink
form support
Browse files Browse the repository at this point in the history
  • Loading branch information
brewster1134 committed Oct 18, 2018
1 parent 5912569 commit 505bdd1
Show file tree
Hide file tree
Showing 7 changed files with 525 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
###### 1.1.0
* serialized value for form support

###### 1.0.13
* added element to data object for tracking jquery elements

Expand Down
2 changes: 1 addition & 1 deletion lib/atrackt.console.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
/*
Atrackt Tracking Library
https://github.com/brewster1134/atrackt
@version 1.0.13
@version 1.1.0
@author Ryan Brewster
*/
(function (factory) {
Expand Down
4 changes: 2 additions & 2 deletions lib/atrackt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
/*
Atrackt Tracking Library
https://github.com/brewster1134/atrackt
@version 1.0.13
@version 1.1.0
@author Ryan Brewster
*/
(function (factory) {
Expand Down Expand Up @@ -397,7 +397,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}, {
key: '_getValue',
value: function _getValue($el) {
return $el.data('atrackt-value') || $el.val() || $el.attr('title') || $el.attr('name') || $el.text().trim() || $el.attr('id') || $el.attr('class');
return $el.data('atrackt-value') || ($el.is('form') ? $el.serializeArray() : $el.val()) || $el.attr('title') || $el.attr('name') || $el.text().trim() || $el.attr('id') || $el.attr('class');
}
}]);

Expand Down
51 changes: 43 additions & 8 deletions spec/atrackt_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ describe 'Atrackt', ->
beforeCallbackSpy.resetHistory()
afterCallbackSpy.resetHistory()
pluginSpy.resetHistory()

context 'when tracking an object', ->
context 'when tracking anything', ->
before ->
Atrackt.plugins['foo-plugin'].track
track_data: true
Expand All @@ -211,7 +211,7 @@ describe 'Atrackt', ->

clock.tick 0

it 'should call the send method on plugins with data and options', ->
it 'should allow tracking extra data and options', ->
expect(pluginSpy).to.be.calledWithExactly
_location: 'Atrackt Test'
global_data: true
Expand All @@ -223,14 +223,28 @@ describe 'Atrackt', ->
plugin_option: true
track_option: true

context 'when tracking an object', ->
before ->
Atrackt.plugins['foo-plugin'].track
track_data: true

clock.tick 0

it 'should call the send method on plugins with data and options', ->
expect(pluginSpy).to.be.calledWithExactly
_location: 'Atrackt Test'
global_data: true
plugin_data: true
track_data: true
,
global_option: true
plugin_option: true

context 'when tracking an element', ->
before ->
@$fooEl = $('<a data-atrackt-category="Anchor" data-atrackt-value="Foo"></a>')

Atrackt.plugins['foo-plugin'].track @$fooEl,
track_option: true
_data:
option_data: true

clock.tick 0

Expand All @@ -242,11 +256,32 @@ describe 'Atrackt', ->
_value: 'Foo'
global_data: true
plugin_data: true
option_data: true
,
global_option: true
plugin_option: true
track_option: true

context 'when tracking a form', ->
before ->
@$fooEl = $('<form data-atrackt-category="Form"><input name="form_input" value="form_value"/></form>')

Atrackt.plugins['foo-plugin'].track @$fooEl,

clock.tick 0

it 'should have an object for the value', ->
expect(pluginSpy).to.be.calledWithExactly
_el: @$fooEl[0]
_location: 'Atrackt Test'
_categories: ['Form']
_value: [
name: 'form_input'
value: 'form_value'
]
global_data: true
plugin_data: true
,
global_option: true
plugin_option: true

context 'when tracking by event', ->
before ->
Expand Down
7 changes: 5 additions & 2 deletions src/atrackt.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###
Atrackt Tracking Library
https://github.com/brewster1134/atrackt
@version 1.0.13
@version 1.1.0
@author Ryan Brewster
###

Expand Down Expand Up @@ -273,7 +273,10 @@ https://github.com/brewster1134/atrackt
#
_getValue: ($el) ->
$el.data('atrackt-value') ||
$el.val() ||
if $el.is 'form'
$el.serializeArray()
else
$el.val() ||
$el.attr('title') ||
$el.attr('name') ||
$el.text().trim() ||
Expand Down
2 changes: 1 addition & 1 deletion src/atrackt.console.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###
Atrackt Tracking Library
https://github.com/brewster1134/atrackt
@version 1.0.13
@version 1.1.0
@author Ryan Brewster
###

Expand Down
Loading

0 comments on commit 505bdd1

Please sign in to comment.