diff --git a/lib/atrackt.console.js b/lib/atrackt.console.js index d93d2bf..4a583fe 100644 --- a/lib/atrackt.console.js +++ b/lib/atrackt.console.js @@ -3,7 +3,7 @@ /* Atrackt Tracking Library https://github.com/brewster1134/atrackt -@version 1.0.2 +@version 1.0.5 @author Ryan Brewster */ @@ -34,6 +34,7 @@ https://github.com/brewster1134/atrackt this.$console = $(consoleHtml); $('#atrackt-location', this.$console).text(this._getLocation()); $('body').addClass('atrackt-console').prepend(this.$console); + this._setPlugins(); this._renderConsoleElements(); } @@ -47,6 +48,21 @@ https://github.com/brewster1134/atrackt } }; + AtracktConsole.prototype._setPlugins = function() { + var plugin, pluginName, _ref, _results; + _ref = this.plugins; + _results = []; + for (pluginName in _ref) { + plugin = _ref[pluginName]; + if (!plugin._send) { + _results.push(this.setPlugin(pluginName, plugin)); + } else { + _results.push(void 0); + } + } + return _results; + }; + AtracktConsole.prototype._renderConsoleElements = function() { var element, elements, eventType, plugin, pluginName, _i, _len, _ref, _ref1, _results; $('tbody', this.$console).empty(); @@ -113,15 +129,17 @@ https://github.com/brewster1134/atrackt $trackEl.addClass('atrackt-console-active'); if ($.scrollTo) { if (this === $rowEl[0]) { - console.log('row'); return $.scrollTo($trackEl, 0, { offset: { top: -300 } }); } else if (this === $trackEl[0]) { - console.log('element'); - return self.$console.scrollTo($rowEl, 0); + return self.$console.scrollTo($rowEl, 0, { + offset: { + top: -100 + } + }); } } }, function() { diff --git a/lib/plugins/atrackt.omniture.js b/lib/plugins/atrackt.omniture.js index b71a2d6..deadeb1 100644 --- a/lib/plugins/atrackt.omniture.js +++ b/lib/plugins/atrackt.omniture.js @@ -4,33 +4,34 @@ Atrackt Omniture Plugin https://github.com/brewster1134/atrackt @author Ryan Brewster -@version 1.0.2 +@version 1.0.5 */ (function() { (function(root, factory) { if (typeof define === 'function' && define.amd) { - return define(['atrackt'], function(Atrackt) { - return factory(Atrackt); + return define(['jquery', 'atrackt'], function($, Atrackt) { + return factory($, Atrackt); }); } else { - return factory(Atrackt); + return factory($, Atrackt); } - })(this, function(Atrackt) { + })(this, function($, Atrackt) { return window.Atrackt.setPlugin('omniture', { send: function(data, options) { var arg, _ref, _ref1; if (typeof s === 'undefined') { return console.error('ATRACKT ERROR: PLUGIN `omniture` - Site catalyst library not loaded'); } + $.extend(true, this.options, options); data._categories = (_ref = data._categories) != null ? _ref.join(this.options.delimiters.category) : void 0; - data = this.translatePropMap(data); - this.buildSObject(data); - if (options.page && (s.t != null)) { + data = this._translatePropMap(data); + this._buildSObject(data); + if (this.options.page && (s.t != null)) { s.t(); } else if (s.tl != null) { - arg = ((_ref1 = options.el) != null ? _ref1.attr('href') : void 0) ? options.el[0] : true; - s.tl(arg, options['trackingType'], this.buildLinkName(data)); + arg = ((_ref1 = this.options.el) != null ? _ref1.attr('href') : void 0) ? this.options.el[0] : true; + s.tl(arg, this.options['trackingType'], this._buildLinkName(data)); } return data; }, @@ -50,7 +51,7 @@ https://github.com/brewster1134/atrackt _event: 'prop4' } }, - buildSObject: function(obj) { + _buildSObject: function(obj) { var key, linkTrackVars, value; switch (this.options.version) { case 14: @@ -67,12 +68,12 @@ https://github.com/brewster1134/atrackt } return s; }, - buildLinkName: function(obj) { + _buildLinkName: function(obj) { var linkName; linkName = [obj[this.options.propMap._location], obj[this.options.propMap._categories], obj[this.options.propMap._value]]; return linkName.join(this.options.delimiters.linkName); }, - translatePropMap: function(obj) { + _translatePropMap: function(obj) { var _globalData; if (this.options.version > 14) { return obj; @@ -81,12 +82,12 @@ https://github.com/brewster1134/atrackt $.each(obj, (function(_this) { return function(k, v) { var _base; - return _globalData[_this.keyLookup(k)] = v != null ? typeof (_base = v.toString()).replace === "function" ? _base.replace(_this.options.charReplaceRegex, '') : void 0 : void 0; + return _globalData[_this._keyLookup(k)] = v != null ? typeof (_base = v.toString()).replace === "function" ? _base.replace(_this.options.charReplaceRegex, '') : void 0 : void 0; }; })(this)); return _globalData; }, - keyLookup: function(key) { + _keyLookup: function(key) { var _newKey; _newKey = this.options.propMap[key]; if (!_newKey) { diff --git a/src/README.md b/src/README.md index 26375f6..ef60591 100644 --- a/src/README.md +++ b/src/README.md @@ -1,4 +1,8 @@ ### CHANGE LOG +###### 1.0.5 +* console scroll fix +* console sets existing plugins on load + ###### 1.0.4 * console loads after document ready and collects all existing element * console now has scrolling support on hover diff --git a/src/atrackt.console.coffee b/src/atrackt.console.coffee index 2c8aa2c..d1904b1 100644 --- a/src/atrackt.console.coffee +++ b/src/atrackt.console.coffee @@ -1,7 +1,7 @@ ### Atrackt Tracking Library https://github.com/brewster1134/atrackt -@version 1.0.2 +@version 1.0.5 @author Ryan Brewster ### @@ -46,6 +46,7 @@ https://github.com/brewster1134/atrackt $('#atrackt-location', @$console).text @_getLocation() $('body').addClass('atrackt-console').prepend @$console + @_setPlugins() @_renderConsoleElements() # Override the custom class to just log tracking data to the console @@ -59,6 +60,11 @@ https://github.com/brewster1134/atrackt plugin.send = (data, options) -> console.log plugin.name, data, options + _setPlugins: -> + for pluginName, plugin of @plugins + unless plugin._send + @setPlugin pluginName, plugin + # Re-render console elements # _renderConsoleElements: -> @@ -129,9 +135,9 @@ https://github.com/brewster1134/atrackt offset: top: -300 else if @ == $trackEl[0] - self.$console.scrollTo $rowEl, 0 + self.$console.scrollTo $rowEl, 0, offset: - top: -50 + top: -100 , -> $rowEl.removeClass 'atrackt-console-active' $trackEl.removeClass 'atrackt-console-active' diff --git a/src/plugins/README.md b/src/plugins/README.md index 64ab30c..86d4a82 100644 --- a/src/plugins/README.md +++ b/src/plugins/README.md @@ -14,6 +14,9 @@ * Just a simple send method! ##### Omniture Plugin +###### 1.0.5 +* options bugfix + ###### 1.0.0 * updated to new api diff --git a/src/plugins/atrackt.omniture.coffee b/src/plugins/atrackt.omniture.coffee index f258ade..d76f3a3 100644 --- a/src/plugins/atrackt.omniture.coffee +++ b/src/plugins/atrackt.omniture.coffee @@ -2,35 +2,37 @@ Atrackt Omniture Plugin https://github.com/brewster1134/atrackt @author Ryan Brewster -@version 1.0.2 +@version 1.0.5 ### ((root, factory) -> if typeof define == 'function' && define.amd define [ + 'jquery' 'atrackt' - ], (Atrackt) -> - factory Atrackt + ], ($, Atrackt) -> + factory $, Atrackt else - factory Atrackt -) @, (Atrackt) -> + factory $, Atrackt +) @, ($, Atrackt) -> window.Atrackt.setPlugin 'omniture', send: (data, options) -> return console.error 'ATRACKT ERROR: PLUGIN `omniture` - Site catalyst library not loaded' if typeof s == 'undefined' + $.extend true, @options, options data._categories = data._categories?.join @options.delimiters.category - data = @translatePropMap data + data = @_translatePropMap data - @buildSObject data - if options.page && s.t? + @_buildSObject data + if @options.page && s.t? s.t() else if s.tl? - arg = if options.el?.attr('href') - options.el[0] + arg = if @options.el?.attr('href') + @options.el[0] else true - s.tl arg, options['trackingType'], @buildLinkName data + s.tl arg, @options['trackingType'], @_buildLinkName data data options: @@ -48,7 +50,7 @@ https://github.com/brewster1134/atrackt _event : 'prop4' # omniture specific - buildSObject: (obj) -> + _buildSObject: (obj) -> switch @options.version when 14 linkTrackVars = @options.linkTrackVars @@ -61,7 +63,7 @@ https://github.com/brewster1134/atrackt s.contextData = obj s - buildLinkName: (obj) -> + _buildLinkName: (obj) -> linkName = [ obj[@options.propMap._location] obj[@options.propMap._categories] @@ -70,15 +72,15 @@ https://github.com/brewster1134/atrackt linkName.join(@options.delimiters.linkName) - translatePropMap: (obj) -> + _translatePropMap: (obj) -> return obj if @options.version > 14 _globalData = {} $.each obj, (k,v) => - _globalData[@keyLookup k] = v?.toString().replace? @options.charReplaceRegex, '' + _globalData[@_keyLookup k] = v?.toString().replace? @options.charReplaceRegex, '' _globalData - keyLookup: (key) -> + _keyLookup: (key) -> _newKey = @options.propMap[key] console.error "ATRACKT ERROR: PLUGIN `omniture` - No mapping for `#{key}` in omniture config" unless _newKey _newKey || key