Skip to content

Commit

Permalink
added element to data object for tracking jquery elements
Browse files Browse the repository at this point in the history
* removed generated by coffeescript header
* convert to dot method syntax
  • Loading branch information
brewster1134 committed Sep 14, 2018
1 parent 0c70c43 commit 5e82b2e
Show file tree
Hide file tree
Showing 14 changed files with 406 additions and 387 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
###### 1.0.13
* added element to data object for tracking jquery elements

###### 1.0.12
* forced hover border when console is enabled

Expand Down
2 changes: 1 addition & 1 deletion demo/atrackt_demo.css.map

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

1 change: 0 additions & 1 deletion demo/atrackt_demo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

// Generated by CoffeeScript 2.2.4
(function () {
$(function () {
Atrackt.setPlugin('Demo Plugin', {
Expand Down
2 changes: 1 addition & 1 deletion lib/atrackt.console.css.map

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

3 changes: 1 addition & 2 deletions lib/atrackt.console.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

// Generated by CoffeeScript 2.2.4
(function () {
/*
Atrackt Tracking Library
https://github.com/brewster1134/atrackt
@version 1.0.0
@version 1.0.13
@author Ryan Brewster
*/
(function (factory) {
Expand Down
26 changes: 13 additions & 13 deletions lib/atrackt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ var _createClass = function () { function defineProperties(target, props) { for

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// Generated by CoffeeScript 2.2.4
(function () {
/*
Atrackt Tracking Library
https://github.com/brewster1134/atrackt
@version 1.0.11
@version 1.0.13
@author Ryan Brewster
*/
(function (factory) {
Expand Down Expand Up @@ -197,7 +196,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var delay, trackPlugins;
if (context != null ? context.name : void 0) {
// Add the plugin name to the options if it exists
options['_plugin'] = context.name;
options._plugin = context.name;
}
trackPlugins = function trackPlugins() {
var eventNamespace, pluginData, pluginName, ref, ref1, results;
Expand All @@ -214,7 +213,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
results.push(void 0);
}
} else {
if (!options['_plugin'] || options['_plugin'] === pluginName) {
if (!options._plugin || options._plugin === pluginName) {
// track jQuery objects
if (data instanceof jQuery) {
results.push(_this3._trackJqueryObject(pluginData, data, options, event));
Expand All @@ -230,7 +229,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return results;
};
// track with optional delay (in milliseconds)
delay = options['delay'];
delay = options.delay;
if (delay) {
return setTimeout(function () {
return trackPlugins();
Expand Down Expand Up @@ -293,21 +292,21 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
throw new Error('ATRACKT ERROR: `track` - Only valid selectors, jquery objects, or html nodes are supported.');
}
// prepare tracking data
trackingData = $.extend(true, {}, this._data, plugin._data, options['_data'] || {}, metaData);
trackingData = $.extend(true, {}, this._data, plugin._data, options._data || {}, metaData);
// remove any data in the options & plugin options in the global options
optionsCopy = $.extend(true, {}, options, options[plugin.name] || {});
delete optionsCopy['_data'];
delete optionsCopy._data;
delete optionsCopy[plugin.name];
trackingOptions = $.extend(true, {}, this._options, plugin._options, optionsCopy);
ref = this._callbacks['before'] || [];
ref = this._callbacks.before || [];
// run global before callbacks
for (i = 0, len = ref.length; i < len; i++) {
callback = ref[i];
if (typeof callback === "function") {
callback(trackingData, trackingOptions);
}
}
ref1 = plugin._callbacks['before'] || [];
ref1 = plugin._callbacks.before || [];
// run plugin before callbacks
for (j = 0, len1 = ref1.length; j < len1; j++) {
callback = ref1[j];
Expand All @@ -323,15 +322,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}
// call plugin's send method
plugin.send(trackingData, trackingOptions);
ref2 = plugin._callbacks['after'] || [];
ref2 = plugin._callbacks.after || [];
// run plugin after callbacks
for (k = 0, len2 = ref2.length; k < len2; k++) {
callback = ref2[k];
if (typeof callback === "function") {
callback(trackingData, trackingOptions);
}
}
ref3 = this._callbacks['after'] || [];
ref3 = this._callbacks.after || [];
// run global after callbacks
results = [];
for (l = 0, len3 = ref3.length; l < len3; l++) {
Expand All @@ -353,15 +352,16 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
if (data instanceof jQuery || data.nodeType === 1) {
$el = $(data);
data = {
_el: data,
_categories: this._getCategories($el),
_value: this._getValue($el)
};
}
// add location
data['_location'] = this._getLocation();
data._location = this._getLocation();
// add event if it exists
if (event != null ? event.type : void 0) {
data['_event'] = event.type;
data._event = event.type;
}
return data;
}
Expand Down
1 change: 0 additions & 1 deletion lib/plugins/atrackt.omniture.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

// Generated by CoffeeScript 2.2.4
(function () {
/*
Atrackt Omniture Plugin
Expand Down
1 change: 0 additions & 1 deletion lib/plugins/atrackt.sumologic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

// Generated by CoffeeScript 2.2.4
(function () {
/*
Atrackt Sumo Logic Plugin
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
"name": "Atrackt",
"license": "SEE LICENSE IN LICENSE FILE",
"engines": {
"node": "~10.6",
"npm": "~6.2"
"node": "^10.6",
"npm": "^6.2"
},
"dependencies": {
"jquery": "~3.3",
"jquery.scrollto": "~2.1"
"jquery": "^3.3",
"jquery.scrollto": "^2.1"
},
"devDependencies": {
"//": "warning [email protected]: Regression introduced (https://github.com/sinonjs/sinon/issues/1756). Use 4.4.9",
"babel-core": "^6.26.3",
"babel-preset-es2015": "^6.24.1",
"chai": "~4.1",
"chai-as-promised": "~7.1",
"coffeescript": "~2.2",
"lolex": "~2.3",
"mocha": "~5.0",
"node-sass": "~4.7",
"phantomjs": "^2.1.7",
"sinon": "~4.4.9",
"sinon-chai": "~3.0",
"testem": "~2.0"
"babel-core": "^6.26",
"babel-preset-es2015": "^6.24",
"chai": "^4.1",
"chai-as-promised": "^7.1",
"coffeescript": "^2.2",
"lolex": "^2.3",
"mocha": "^5.0",
"node-sass": "^4.7",
"phantomjs": "^2.1",
"sinon": "^4.4.9",
"sinon-chai": "^3.0",
"testem": "^2.0"
}
}
33 changes: 19 additions & 14 deletions spec/atrackt_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ describe 'Atrackt', ->

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

Atrackt.plugins['foo-plugin'].track $fooEl,
Atrackt.plugins['foo-plugin'].track @$fooEl,
track_option: true
_data:
option_data: true
Expand All @@ -236,6 +236,7 @@ describe 'Atrackt', ->

it 'should call the send method on plugins with data and options', ->
expect(pluginSpy).to.be.calledWithExactly
_el: @$fooEl[0]
_location: 'Atrackt Test'
_categories: ['Anchor']
_value: 'Foo'
Expand All @@ -249,18 +250,19 @@ describe 'Atrackt', ->

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

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

$fooEl.trigger 'click'
@$fooEl.trigger 'click'

clock.tick 0

it 'should call the send method on plugins with data and options', ->
expect(pluginSpy).to.be.calledWithExactly
_el: @$fooEl[0]
_location: 'Atrackt Test'
_categories: ['Anchor']
_value: 'Foo'
Expand All @@ -273,20 +275,21 @@ describe 'Atrackt', ->

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

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

$fooEl.trigger 'click'
@$fooEl.trigger 'click'

clock.tick 0

it 'should call the send method on plugins with data and options', ->
expect(pluginSpy).to.be.calledWithExactly
_el: @$fooEl[0]
_location: 'Atrackt Test'
_categories: []
_value: 'Foo'
Expand All @@ -301,9 +304,9 @@ describe 'Atrackt', ->

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

Atrackt.track $fooEl,
Atrackt.track @$fooEl,
global_option: 'global'
global_only: true
'foo-plugin':
Expand All @@ -314,6 +317,7 @@ describe 'Atrackt', ->

it 'should call send with proper data & options', ->
expect(pluginSpy).to.be.calledWithExactly
_el: @$fooEl[0]
_location: 'Atrackt Test'
_categories: []
_value: 'Foo'
Expand All @@ -326,15 +330,16 @@ describe 'Atrackt', ->

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

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

clock.tick 0

it 'should call send with proper data & options', ->
expect(pluginSpy).to.be.calledWithExactly
_el: @$fooEl[0]
_location: 'Atrackt Test'
_categories: []
_value: 'Foo'
Expand Down
Loading

0 comments on commit 5e82b2e

Please sign in to comment.