Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

autotrack

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

autotrack - npm Package Compare versions

Comparing version 0.6.4 to 0.6.5

test/utilities.js

4

autotrack.js

@@ -18,4 +18,4 @@ /**

/*! autotrack.js v0.6.4 */
!function t(e,i,n){function r(o,s){if(!i[o]){if(!e[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var d=i[o]={exports:{}};e[o][0].call(d.exports,function(t){var i=e[o][1][t];return r(i?i:t)},d,d.exports,t,e,i,n)}return i[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)r(n[o]);return r}({1:[function(t,e,i){e.exports={DEV_ID:"i5iSjo"}},{}],2:[function(t,e,i){function n(t,e){if(window.addEventListener){this.opts=a(e,{attributePrefix:"data-"}),this.tracker=t;var i=this.opts.attributePrefix,n="["+i+"event-category]["+i+"event-action]";this.delegate=r(document,n,"click",this.handleEventClicks.bind(this))}}var r=t("delegate"),a=t("../utilities").defaults,o=t("../provide");n.prototype.handleEventClicks=function(t){var e=t.delegateTarget,i=this.opts.attributePrefix;this.tracker.send("event",{eventCategory:e.getAttribute(i+"event-category"),eventAction:e.getAttribute(i+"event-action"),eventLabel:e.getAttribute(i+"event-label"),eventValue:e.getAttribute(i+"event-value")})},n.prototype.remove=function(){this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null},o("eventTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],3:[function(t,e,i){function n(t,e){window.matchMedia&&(this.opts=o(e,{mediaQueryDefinitions:!1,mediaQueryChangeTemplate:this.changeTemplate,mediaQueryChangeTimeout:1e3}),s(this.opts.mediaQueryDefinitions)&&(this.opts.mediaQueryDefinitions=l(this.opts.mediaQueryDefinitions),this.tracker=t,this.changeListeners=[],this.processMediaQueries()))}function r(t){return c[t]?c[t]:(c[t]=window.matchMedia(t),c[t])}var a=t("debounce"),o=t("../utilities").defaults,s=t("../utilities").isObject,l=t("../utilities").toArray,u=t("../provide"),d="(not set)",c={};n.prototype.processMediaQueries=function(){this.opts.mediaQueryDefinitions.forEach(function(t){if(t.name&&t.dimensionIndex){var e=this.getMatchName(t);this.tracker.set("dimension"+t.dimensionIndex,e),this.addChangeListeners(t)}}.bind(this))},n.prototype.getMatchName=function(t){var e;return t.items.forEach(function(t){r(t.media).matches&&(e=t)}),e?e.name:d},n.prototype.addChangeListeners=function(t){t.items.forEach(function(e){var i=r(e.media),n=a(function(){this.handleChanges(t)}.bind(this),this.opts.mediaQueryChangeTimeout);i.addListener(n),this.changeListeners.push({mql:i,fn:n})}.bind(this))},n.prototype.handleChanges=function(t){var e=this.getMatchName(t),i=this.tracker.get("dimension"+t.dimensionIndex);e!==i&&(this.tracker.set("dimension"+t.dimensionIndex,e),this.tracker.send("event",t.name,"change",this.opts.mediaQueryChangeTemplate(i,e)))},n.prototype.remove=function(){for(var t,e=0;t=this.changeListeners[e];e++)t.mql.removeListener(t.fn);this.changeListeners=null,this.tracker=null,this.opts=null},n.prototype.changeTemplate=function(t,e){return t+" => "+e},u("mediaQueryTracker",n)},{"../provide":8,"../utilities":9,debounce:12}],4:[function(t,e,i){function n(t,e){window.addEventListener&&(this.opts=r(e,{shouldTrackOutboundForm:this.shouldTrackOutboundForm}),this.tracker=t,this.delegate=a(document,"form","submit",this.handleFormSubmits.bind(this)))}var r=t("../utilities").defaults,a=t("delegate"),o=t("../provide"),s=t("../utilities");n.prototype.handleFormSubmits=function(t){var e=t.delegateTarget,i=e.getAttribute("action"),n={transport:"beacon"};this.opts.shouldTrackOutboundForm(e)&&(navigator.sendBeacon||(t.preventDefault(),n.hitCallback=s.withTimeout(function(){e.submit()})),this.tracker.send("event","Outbound Form","submit",i,n))},n.prototype.shouldTrackOutboundForm=function(t){var e=t.getAttribute("action");return e&&0===e.indexOf("http")&&e.indexOf(location.hostname)<0},n.prototype.remove=function(){this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null},o("outboundFormTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],5:[function(t,e,i){function n(t,e){window.addEventListener&&(this.opts=r(e,{shouldTrackOutboundLink:this.shouldTrackOutboundLink}),this.tracker=t,this.delegate=a(document,"a","click",this.handleLinkClicks.bind(this)))}var r=t("../utilities").defaults,a=t("delegate"),o=t("../provide");n.prototype.handleLinkClicks=function(t){var e=t.delegateTarget;this.opts.shouldTrackOutboundLink(e)&&(navigator.sendBeacon||(e.target="_blank"),this.tracker.send("event","Outbound Link","click",e.href,{transport:"beacon"}))},n.prototype.shouldTrackOutboundLink=function(t){return t.hostname!=location.hostname&&0===t.protocol.indexOf("http")},n.prototype.remove=function(){this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null},o("outboundLinkTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],6:[function(t,e,i){function n(t,e){if(window.addEventListener){this.opts=r(e,{attributePrefix:"data-"}),this.tracker=t;var i=this.opts.attributePrefix,n="["+i+"social-network]["+i+"social-action]["+i+"social-target]";this.handleSocialClicks=this.handleSocialClicks.bind(this),this.addWidgetListeners=this.addWidgetListeners.bind(this),this.addTwitterEventHandlers=this.addTwitterEventHandlers.bind(this),this.handleTweetEvents=this.handleTweetEvents.bind(this),this.handleFollowEvents=this.handleFollowEvents.bind(this),this.handleLikeEvents=this.handleLikeEvents.bind(this),this.handleUnlikeEvents=this.handleUnlikeEvents.bind(this),this.delegate=a(document,n,"click",this.handleSocialClicks),"complete"!=document.readyState?window.addEventListener("load",this.addWidgetListeners):this.addWidgetListeners()}}var r=t("../utilities").defaults,a=t("delegate"),o=t("../provide");n.prototype.addWidgetListeners=function(){window.FB&&this.addFacebookEventHandlers(),window.twttr&&this.addTwitterEventHandlers()},n.prototype.handleSocialClicks=function(t){var e=t.delegateTarget,i=this.opts.attributePrefix;this.tracker.send("social",{socialNetwork:e.getAttribute(i+"social-network"),socialAction:e.getAttribute(i+"social-action"),socialTarget:e.getAttribute(i+"social-target")})},n.prototype.addTwitterEventHandlers=function(){try{twttr.ready(function(){twttr.events.bind("tweet",this.handleTweetEvents),twttr.events.bind("follow",this.handleFollowEvents)}.bind(this))}catch(t){}},n.prototype.removeTwitterEventHandlers=function(){try{twttr.ready(function(){twttr.events.unbind("tweet",this.handleTweetEvents),twttr.events.unbind("follow",this.handleFollowEvents)}.bind(this))}catch(t){}},n.prototype.addFacebookEventHandlers=function(){try{FB.Event.subscribe("edge.create",this.handleLikeEvents),FB.Event.subscribe("edge.remove",this.handleUnlikeEvents)}catch(t){}},n.prototype.removeFacebookEventHandlers=function(){try{FB.Event.unsubscribe("edge.create",this.handleLikeEvents),FB.Event.unsubscribe("edge.remove",this.handleUnlikeEvents)}catch(t){}},n.prototype.handleTweetEvents=function(t){if("tweet"==t.region){var e=t.data.url||t.target.getAttribute("data-url")||location.href;this.tracker.send("social","Twitter","tweet",e)}},n.prototype.handleFollowEvents=function(t){if("follow"==t.region){var e=t.data.screen_name||t.target.getAttribute("data-screen-name");this.tracker.send("social","Twitter","follow",e)}},n.prototype.handleLikeEvents=function(t){this.tracker.send("social","Facebook","like",t)},n.prototype.handleUnlikeEvents=function(t){this.tracker.send("social","Facebook","unlike",t)},n.prototype.remove=function(){window.removeEventListener("load",this.addWidgetListeners),this.removeFacebookEventHandlers(),this.removeTwitterEventHandlers(),this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null,this.handleSocialClicks=null,this.addWidgetListeners=null,this.addTwitterEventHandlers=null,this.handleTweetEvents=null,this.handleFollowEvents=null,this.handleLikeEvents=null,this.handleUnlikeEvents=null},o("socialTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],7:[function(t,e,i){function n(t,e){history.pushState&&window.addEventListener&&(this.opts=a(e,{shouldTrackUrlChange:this.shouldTrackUrlChange}),this.tracker=t,this.path=r(),this.updateTrackerData=this.updateTrackerData.bind(this),this.originalPushState=history.pushState,history.pushState=function(t,e,i){o(t)&&e&&(t.title=e),this.originalPushState.call(history,t,e,i),this.updateTrackerData()}.bind(this),this.originalReplaceState=history.replaceState,history.replaceState=function(t,e,i){o(t)&&e&&(t.title=e),this.originalReplaceState.call(history,t,e,i),this.updateTrackerData(!1)}.bind(this),window.addEventListener("popstate",this.updateTrackerData))}function r(){return location.pathname+location.search}var a=t("../utilities").defaults,o=t("../utilities").isObject,s=t("../provide");n.prototype.updateTrackerData=function(t){t=t===!1?!1:!0,setTimeout(function(){var e=this.path,i=r();e!=i&&this.opts.shouldTrackUrlChange.call(this,i,e)&&(this.path=i,this.tracker.set({page:i,title:o(history.state)&&history.state.title||document.title}),t&&this.tracker.send("pageview"))}.bind(this),0)},n.prototype.shouldTrackUrlChange=function(t,e){return!0},n.prototype.remove=function(){window.removeEventListener("popstate",this.updateTrackerData),history.replaceState=this.originalReplaceState,history.pushState=this.originalPushState,this.tracker=null,this.opts=null,this.path=null,this.updateTrackerData=null,this.originalReplaceState=null,this.originalPushState=null},s("urlChangeTracker",n)},{"../provide":8,"../utilities":9}],8:[function(t,e,i){var n=t("./constants"),r=t("./utilities");(window.gaDevIds=window.gaDevIds||[]).push(n.DEV_ID),e.exports=function(t,e){var i=window.GoogleAnalyticsObject||"ga";window[i]=window[i]||function(){(window[i].q=window[i].q||[]).push(arguments)},window[i]("provide",t,e),window.gaplugins=window.gaplugins||{},window.gaplugins[r.capitalize(t)]=e}},{"./constants":1,"./utilities":9}],9:[function(t,e,i){var n={withTimeout:function(t,e){var i=!1;return setTimeout(t,e||2e3),function(){i||(i=!0,t())}},defaults:function(t,e){var i={};"object"!=typeof t&&(t={}),"object"!=typeof e&&(e={});for(var n in e)e.hasOwnProperty(n)&&(i[n]=t.hasOwnProperty(n)?t[n]:e[n]);return i},capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},isObject:function(t){return"object"==typeof t&&null!==t},isArray:Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},toArray:function(t){return n.isArray(t)?t:[t]}};e.exports=n},{}],10:[function(t,e,i){var n=t("matches-selector");e.exports=function(t,e,i){for(var r=i?t:t.parentNode;r&&r!==document;){if(n(r,e))return r;r=r.parentNode}}},{"matches-selector":14}],11:[function(t,e,i){function n(){return(new Date).getTime()}e.exports=Date.now||n},{}],12:[function(t,e,i){var n=t("date-now");e.exports=function(t,e,i){function r(){var d=n()-l;e>d&&d>0?a=setTimeout(r,e-d):(a=null,i||(u=t.apply(s,o),a||(s=o=null)))}var a,o,s,l,u;return null==e&&(e=100),function(){s=this,o=arguments,l=n();var d=i&&!a;return a||(a=setTimeout(r,e)),d&&(u=t.apply(s,o),s=o=null),u}}},{"date-now":11}],13:[function(t,e,i){function n(t,e,i,n,a){var o=r.apply(this,arguments);return t.addEventListener(i,o,a),{destroy:function(){t.removeEventListener(i,o,a)}}}function r(t,e,i,n){return function(i){i.delegateTarget=a(i.target,e,!0),i.delegateTarget&&n.call(t,i)}}var a=t("closest");e.exports=n},{closest:10}],14:[function(t,e,i){function n(t,e){if(a)return a.call(t,e);for(var i=t.parentNode.querySelectorAll(e),n=0;n<i.length;++n)if(i[n]==t)return!0;return!1}var r=Element.prototype,a=r.matchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector||r.msMatchesSelector||r.oMatchesSelector;e.exports=n},{}],15:[function(t,e,i){function n(t,e){var i=window[window.GoogleAnalyticsObject||"ga"],n=t.get("name");i(n+".require","eventTracker",e),i(n+".require","mediaQueryTracker",e),i(n+".require","outboundFormTracker",e),i(n+".require","outboundLinkTracker",e),i(n+".require","socialTracker",e),i(n+".require","urlChangeTracker",e)}t("./event-tracker"),t("./media-query-tracker"),t("./outbound-form-tracker"),t("./outbound-link-tracker"),t("./social-tracker"),t("./url-change-tracker");var r=t("../provide");r("autotrack",n)},{"../provide":8,"./event-tracker":2,"./media-query-tracker":3,"./outbound-form-tracker":4,"./outbound-link-tracker":5,"./social-tracker":6,"./url-change-tracker":7}]},{},[15]);
/*! autotrack.js v0.6.5 */
!function t(e,i,n){function r(o,s){if(!i[o]){if(!e[o]){var l="function"==typeof require&&require;if(!s&&l)return l(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var d=i[o]={exports:{}};e[o][0].call(d.exports,function(t){var i=e[o][1][t];return r(i?i:t)},d,d.exports,t,e,i,n)}return i[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)r(n[o]);return r}({1:[function(t,e,i){e.exports={DEV_ID:"i5iSjo"}},{}],2:[function(t,e,i){function n(t,e){if(window.addEventListener){this.opts=a(e,{attributePrefix:"data-"}),this.tracker=t;var i=this.opts.attributePrefix,n="["+i+"event-category]["+i+"event-action]";this.delegate=r(document,n,"click",this.handleEventClicks.bind(this))}}var r=t("delegate"),a=t("../utilities").defaults,o=t("../provide");n.prototype.handleEventClicks=function(t){var e=t.delegateTarget,i=this.opts.attributePrefix;this.tracker.send("event",{eventCategory:e.getAttribute(i+"event-category"),eventAction:e.getAttribute(i+"event-action"),eventLabel:e.getAttribute(i+"event-label"),eventValue:e.getAttribute(i+"event-value")})},n.prototype.remove=function(){this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null},o("eventTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],3:[function(t,e,i){function n(t,e){window.matchMedia&&(this.opts=o(e,{mediaQueryDefinitions:!1,mediaQueryChangeTemplate:this.changeTemplate,mediaQueryChangeTimeout:1e3}),s(this.opts.mediaQueryDefinitions)&&(this.opts.mediaQueryDefinitions=l(this.opts.mediaQueryDefinitions),this.tracker=t,this.changeListeners=[],this.processMediaQueries()))}function r(t){return c[t]?c[t]:(c[t]=window.matchMedia(t),c[t])}var a=t("debounce"),o=t("../utilities").defaults,s=t("../utilities").isObject,l=t("../utilities").toArray,u=t("../provide"),d="(not set)",c={};n.prototype.processMediaQueries=function(){this.opts.mediaQueryDefinitions.forEach(function(t){if(t.name&&t.dimensionIndex){var e=this.getMatchName(t);this.tracker.set("dimension"+t.dimensionIndex,e),this.addChangeListeners(t)}}.bind(this))},n.prototype.getMatchName=function(t){var e;return t.items.forEach(function(t){r(t.media).matches&&(e=t)}),e?e.name:d},n.prototype.addChangeListeners=function(t){t.items.forEach(function(e){var i=r(e.media),n=a(function(){this.handleChanges(t)}.bind(this),this.opts.mediaQueryChangeTimeout);i.addListener(n),this.changeListeners.push({mql:i,fn:n})}.bind(this))},n.prototype.handleChanges=function(t){var e=this.getMatchName(t),i=this.tracker.get("dimension"+t.dimensionIndex);e!==i&&(this.tracker.set("dimension"+t.dimensionIndex,e),this.tracker.send("event",t.name,"change",this.opts.mediaQueryChangeTemplate(i,e)))},n.prototype.remove=function(){for(var t,e=0;t=this.changeListeners[e];e++)t.mql.removeListener(t.fn);this.changeListeners=null,this.tracker=null,this.opts=null},n.prototype.changeTemplate=function(t,e){return t+" => "+e},u("mediaQueryTracker",n)},{"../provide":8,"../utilities":9,debounce:12}],4:[function(t,e,i){function n(t,e){window.addEventListener&&(this.opts=r(e,{shouldTrackOutboundForm:this.shouldTrackOutboundForm}),this.tracker=t,this.delegate=a(document,"form","submit",this.handleFormSubmits.bind(this)))}var r=t("../utilities").defaults,a=t("delegate"),o=t("../provide"),s=t("../utilities");n.prototype.handleFormSubmits=function(t){var e=t.delegateTarget,i=e.getAttribute("action"),n={transport:"beacon"};this.opts.shouldTrackOutboundForm(e)&&(navigator.sendBeacon||(t.preventDefault(),n.hitCallback=s.withTimeout(function(){e.submit()})),this.tracker.send("event","Outbound Form","submit",i,n))},n.prototype.shouldTrackOutboundForm=function(t){var e=t.getAttribute("action");return e&&0===e.indexOf("http")&&e.indexOf(location.hostname)<0},n.prototype.remove=function(){this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null},o("outboundFormTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],5:[function(t,e,i){function n(t,e){window.addEventListener&&(this.opts=r(e,{shouldTrackOutboundLink:this.shouldTrackOutboundLink}),this.tracker=t,this.delegate=a(document,"a","click",this.handleLinkClicks.bind(this)))}var r=t("../utilities").defaults,a=t("delegate"),o=t("../provide");n.prototype.handleLinkClicks=function(t){var e=t.delegateTarget;this.opts.shouldTrackOutboundLink(e)&&(navigator.sendBeacon||(e.target="_blank"),this.tracker.send("event","Outbound Link","click",e.href,{transport:"beacon"}))},n.prototype.shouldTrackOutboundLink=function(t){return t.hostname!=location.hostname&&0===t.protocol.indexOf("http")},n.prototype.remove=function(){this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null},o("outboundLinkTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],6:[function(t,e,i){function n(t,e){if(window.addEventListener){this.opts=r(e,{attributePrefix:"data-"}),this.tracker=t;var i=this.opts.attributePrefix,n="["+i+"social-network]["+i+"social-action]["+i+"social-target]";this.handleSocialClicks=this.handleSocialClicks.bind(this),this.addWidgetListeners=this.addWidgetListeners.bind(this),this.addTwitterEventHandlers=this.addTwitterEventHandlers.bind(this),this.handleTweetEvents=this.handleTweetEvents.bind(this),this.handleFollowEvents=this.handleFollowEvents.bind(this),this.handleLikeEvents=this.handleLikeEvents.bind(this),this.handleUnlikeEvents=this.handleUnlikeEvents.bind(this),this.delegate=a(document,n,"click",this.handleSocialClicks),"complete"!=document.readyState?window.addEventListener("load",this.addWidgetListeners):this.addWidgetListeners()}}var r=t("../utilities").defaults,a=t("delegate"),o=t("../provide");n.prototype.addWidgetListeners=function(){window.FB&&this.addFacebookEventHandlers(),window.twttr&&this.addTwitterEventHandlers()},n.prototype.handleSocialClicks=function(t){var e=t.delegateTarget,i=this.opts.attributePrefix;this.tracker.send("social",{socialNetwork:e.getAttribute(i+"social-network"),socialAction:e.getAttribute(i+"social-action"),socialTarget:e.getAttribute(i+"social-target")})},n.prototype.addTwitterEventHandlers=function(){try{twttr.ready(function(){twttr.events.bind("tweet",this.handleTweetEvents),twttr.events.bind("follow",this.handleFollowEvents)}.bind(this))}catch(t){}},n.prototype.removeTwitterEventHandlers=function(){try{twttr.ready(function(){twttr.events.unbind("tweet",this.handleTweetEvents),twttr.events.unbind("follow",this.handleFollowEvents)}.bind(this))}catch(t){}},n.prototype.addFacebookEventHandlers=function(){try{FB.Event.subscribe("edge.create",this.handleLikeEvents),FB.Event.subscribe("edge.remove",this.handleUnlikeEvents)}catch(t){}},n.prototype.removeFacebookEventHandlers=function(){try{FB.Event.unsubscribe("edge.create",this.handleLikeEvents),FB.Event.unsubscribe("edge.remove",this.handleUnlikeEvents)}catch(t){}},n.prototype.handleTweetEvents=function(t){if("tweet"==t.region){var e=t.data.url||t.target.getAttribute("data-url")||location.href;this.tracker.send("social","Twitter","tweet",e)}},n.prototype.handleFollowEvents=function(t){if("follow"==t.region){var e=t.data.screen_name||t.target.getAttribute("data-screen-name");this.tracker.send("social","Twitter","follow",e)}},n.prototype.handleLikeEvents=function(t){this.tracker.send("social","Facebook","like",t)},n.prototype.handleUnlikeEvents=function(t){this.tracker.send("social","Facebook","unlike",t)},n.prototype.remove=function(){window.removeEventListener("load",this.addWidgetListeners),this.removeFacebookEventHandlers(),this.removeTwitterEventHandlers(),this.delegate.destroy(),this.delegate=null,this.tracker=null,this.opts=null,this.handleSocialClicks=null,this.addWidgetListeners=null,this.addTwitterEventHandlers=null,this.handleTweetEvents=null,this.handleFollowEvents=null,this.handleLikeEvents=null,this.handleUnlikeEvents=null},o("socialTracker",n)},{"../provide":8,"../utilities":9,delegate:13}],7:[function(t,e,i){function n(t,e){history.pushState&&window.addEventListener&&(this.opts=a(e,{shouldTrackUrlChange:this.shouldTrackUrlChange}),this.tracker=t,this.path=r(),this.updateTrackerData=this.updateTrackerData.bind(this),this.originalPushState=history.pushState,history.pushState=function(t,e){o(t)&&e&&(t.title=e),this.originalPushState.apply(history,arguments),this.updateTrackerData()}.bind(this),this.originalReplaceState=history.replaceState,history.replaceState=function(t,e){o(t)&&e&&(t.title=e),this.originalReplaceState.apply(history,arguments),this.updateTrackerData(!1)}.bind(this),window.addEventListener("popstate",this.updateTrackerData))}function r(){return location.pathname+location.search}var a=t("../utilities").defaults,o=t("../utilities").isObject,s=t("../provide");n.prototype.updateTrackerData=function(t){t=t!==!1,setTimeout(function(){var e=this.path,i=r();e!=i&&this.opts.shouldTrackUrlChange.call(this,i,e)&&(this.path=i,this.tracker.set({page:i,title:o(history.state)&&history.state.title||document.title}),t&&this.tracker.send("pageview"))}.bind(this),0)},n.prototype.shouldTrackUrlChange=function(t,e){return t&&e},n.prototype.remove=function(){window.removeEventListener("popstate",this.updateTrackerData),history.replaceState=this.originalReplaceState,history.pushState=this.originalPushState,this.tracker=null,this.opts=null,this.path=null,this.updateTrackerData=null,this.originalReplaceState=null,this.originalPushState=null},s("urlChangeTracker",n)},{"../provide":8,"../utilities":9}],8:[function(t,e,i){var n=t("./constants"),r=t("./utilities");(window.gaDevIds=window.gaDevIds||[]).push(n.DEV_ID),e.exports=function(t,e){var i=window.GoogleAnalyticsObject||"ga";window[i]=window[i]||function(){(window[i].q=window[i].q||[]).push(arguments)},window[i]("provide",t,e),window.gaplugins=window.gaplugins||{},window.gaplugins[r.capitalize(t)]=e}},{"./constants":1,"./utilities":9}],9:[function(t,e,i){var n={withTimeout:function(t,e){var i=!1;return setTimeout(t,e||2e3),function(){i||(i=!0,t())}},defaults:function(t,e){var i={};"object"!=typeof t&&(t={}),"object"!=typeof e&&(e={});for(var n in e)e.hasOwnProperty(n)&&(i[n]=t.hasOwnProperty(n)?t[n]:e[n]);return i},capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},isObject:function(t){return"object"==typeof t&&null!==t},isArray:Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},toArray:function(t){return n.isArray(t)?t:[t]}};e.exports=n},{}],10:[function(t,e,i){var n=t("matches-selector");e.exports=function(t,e,i){for(var r=i?t:t.parentNode;r&&r!==document;){if(n(r,e))return r;r=r.parentNode}}},{"matches-selector":14}],11:[function(t,e,i){function n(){return(new Date).getTime()}e.exports=Date.now||n},{}],12:[function(t,e,i){var n=t("date-now");e.exports=function(t,e,i){function r(){var d=n()-l;e>d&&d>0?a=setTimeout(r,e-d):(a=null,i||(u=t.apply(s,o),a||(s=o=null)))}var a,o,s,l,u;return null==e&&(e=100),function(){s=this,o=arguments,l=n();var d=i&&!a;return a||(a=setTimeout(r,e)),d&&(u=t.apply(s,o),s=o=null),u}}},{"date-now":11}],13:[function(t,e,i){function n(t,e,i,n,a){var o=r.apply(this,arguments);return t.addEventListener(i,o,a),{destroy:function(){t.removeEventListener(i,o,a)}}}function r(t,e,i,n){return function(i){i.delegateTarget=a(i.target,e,!0),i.delegateTarget&&n.call(t,i)}}var a=t("closest");e.exports=n},{closest:10}],14:[function(t,e,i){function n(t,e){if(a)return a.call(t,e);for(var i=t.parentNode.querySelectorAll(e),n=0;n<i.length;++n)if(i[n]==t)return!0;return!1}var r=Element.prototype,a=r.matchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector||r.msMatchesSelector||r.oMatchesSelector;e.exports=n},{}],15:[function(t,e,i){function n(t,e){var i=window[window.GoogleAnalyticsObject||"ga"],n=t.get("name");i(n+".require","eventTracker",e),i(n+".require","mediaQueryTracker",e),i(n+".require","outboundFormTracker",e),i(n+".require","outboundLinkTracker",e),i(n+".require","socialTracker",e),i(n+".require","urlChangeTracker",e)}t("./event-tracker"),t("./media-query-tracker"),t("./outbound-form-tracker"),t("./outbound-link-tracker"),t("./social-tracker"),t("./url-change-tracker");var r=t("../provide");r("autotrack",n)},{"../provide":8,"./event-tracker":2,"./media-query-tracker":3,"./outbound-form-tracker":4,"./outbound-link-tracker":5,"./social-tracker":6,"./url-change-tracker":7}]},{},[15]);
//# sourceMappingURL=autotrack.js.map
# Changelog
### 0.6.5 (2016-04-13)
- Fix a history change bug in IE11 (#57)
### 0.6.4 (2016-03-30)

@@ -4,0 +8,0 @@

@@ -18,11 +18,15 @@ /**

/* eslint require-jsdoc: "off" */
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var connect = require('connect');
var eslint = require('gulp-eslint');
var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var ngrok = require('ngrok');
var pkg = require('./package.json');
var seleniumServerJar = require('selenium-server-standalone-jar');
var pkg = require('./package.json');
var shell = require('shelljs');
var serveStatic = require('serve-static');

@@ -37,2 +41,3 @@ var source = require('vinyl-source-stream');

var server;
var seleniumServer;

@@ -70,5 +75,14 @@

gulp.task('test', ['javascript', 'serve', 'selenium'], function() {
gulp.task('lint', function () {
return gulp.src(['gulpfile.js', 'lib/**/*.js', 'test/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('test', ['javascript', 'lint', 'tunnel', 'selenium'], function() {
function stopServers() {
server.close();
ngrok.kill();
if (!process.env.CI) seleniumServer.kill();

@@ -82,2 +96,12 @@ }

gulp.task('tunnel', ['serve'], function(done) {
ngrok.connect(8080, function(err, url) {
if (err) return done(err);
process.env.BASE_URL = url;
done();
});
});
gulp.task('serve', ['javascript'], function(done) {

@@ -84,0 +108,0 @@ server = connect().use(serveStatic('./')).listen(8080, done);

@@ -17,2 +17,3 @@ /**

// Imports sub-plugins.

@@ -19,0 +20,0 @@ require('./event-tracker');

@@ -85,3 +85,3 @@ /**

* If no match is found, the NULL_DIMENSION value is returned.
* @param {Object} dimension A set of named media queries associated
* @param {Object} definition A set of named media queries associated
* with a single custom dimension.

@@ -155,4 +155,4 @@ * @return {string} The name of the matched media or NULL_DIMENSION.

* This can be overridden by setting the `mediaQueryChangeTemplate` option.
* @param {string} oldValue
* @param {string} newValue
* @param {string} oldValue The value of the media query prior to the change.
* @param {string} newValue The value of the media query after the change.
* @return {string} The formatted event label.

@@ -165,3 +165,2 @@ */

/**

@@ -171,3 +170,3 @@ * Accepts a media query and returns a MediaQueryListener object.

* @param {string} media A media query value.
* @return {MediaQueryListener}
* @return {MediaQueryListener} The matched media.
*/

@@ -174,0 +173,0 @@ function getMediaListener(media) {

@@ -18,2 +18,5 @@ /**

/* global FB, twttr */
var defaults = require('../utilities').defaults;

@@ -80,3 +83,3 @@ var delegate = require('delegate');

if (window.twttr) this.addTwitterEventHandlers();
}
};

@@ -156,2 +159,3 @@

* Handles `tweet` events emitted by the Twitter JS SDK.
* @param {Object} event The Twitter event object passed to the handler.
*/

@@ -171,2 +175,3 @@ SocialTracker.prototype.handleTweetEvents = function(event) {

* Handles `follow` events emitted by the Twitter JS SDK.
* @param {Object} event The Twitter event object passed to the handler.
*/

@@ -181,3 +186,3 @@ SocialTracker.prototype.handleFollowEvents = function(event) {

this.tracker.send('social', 'Twitter', 'follow', screenName);
}
};

@@ -187,2 +192,3 @@

* Handles `like` events emitted by the Facebook JS SDK.
* @param {string} url The URL corresponding to the like event.
*/

@@ -196,2 +202,3 @@ SocialTracker.prototype.handleLikeEvents = function(url) {

* Handles `unlike` events emitted by the Facebook JS SDK.
* @param {string} url The URL corresponding to the unlike event.
*/

@@ -198,0 +205,0 @@ SocialTracker.prototype.handleUnlikeEvents = function(url) {

@@ -49,3 +49,3 @@ /**

this.originalPushState = history.pushState;
history.pushState = function(state, title, url) {
history.pushState = function(state, title) {
// Sets the document title for reference later.

@@ -56,3 +56,3 @@ // TODO(philipwalton): consider using WeakMap for this to not conflict

this.originalPushState.call(history, state, title, url);
this.originalPushState.apply(history, arguments);
this.updateTrackerData();

@@ -63,3 +63,3 @@ }.bind(this);

this.originalReplaceState = history.replaceState;
history.replaceState = function(state, title, url) {
history.replaceState = function(state, title) {
// Sets the document title for reference later.

@@ -70,3 +70,3 @@ // TODO(philipwalton): consider using WeakMap for this to not conflict

this.originalReplaceState.call(history, state, title, url);
this.originalReplaceState.apply(history, arguments);
this.updateTrackerData(false);

@@ -83,2 +83,4 @@ }.bind(this);

* optionally sends a pageview.
* @param {boolean} shouldSendPageview Indicates whether the tracker should
* send a pageview after updating the URL.
*/

@@ -115,8 +117,8 @@ UrlChangeTracker.prototype.updateTrackerData = function(shouldSendPageview) {

* data. This default implementation can be overrided in the config options.
* @param {string} newPath
* @param {string} oldPath
* @return {boolean}
* @param {string} newPath The path prior to the URL change.
* @param {string} oldPath The path after the URL change.
* @return {boolean} Whether or not the URL change should be tracked.
*/
UrlChangeTracker.prototype.shouldTrackUrlChange = function(newPath, oldPath) {
return true;
return newPath && oldPath;
};

@@ -144,4 +146,3 @@

/**
* Returns the path value of the current URL.
* @return {string}
* @return {string} The path value of the current URL.
*/

@@ -148,0 +149,0 @@ function getPath() {

@@ -28,2 +28,3 @@ /**

* the callback.
* @returns {Function} The wrapped version of the passed function.
*/

@@ -46,4 +47,5 @@ withTimeout: function(callback, wait) {

* corresponding value in overrides, it gets used.
* @param {Object} overrides.
* @param {?Object} defaults.
* @param {Object} overrides The object with properties to override.
* @param {?Object} defaults The object with properties to use as defaults.
* @return {Object} The final, merged object.
*/

@@ -71,2 +73,7 @@ defaults: function(overrides, defaults) {

/**
* Capitalizes the first letter of a string.
* @param {string} str The input string.
* @return {string} The capitalized string
*/
capitalize: function(str) {

@@ -77,14 +84,30 @@ return str.charAt(0).toUpperCase() + str.slice(1);

isObject: function(obj) {
return typeof obj == 'object' && obj !== null;
/**
* Indicates whether the passed variable is a JavaScript object.
* @param {*} value The input variable to test.
* @return {boolean} Whether or not the test is an object.
*/
isObject: function(value) {
return typeof value == 'object' && value !== null;
},
isArray: Array.isArray || function(arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
/**
* Indicates whether the passed variable is a JavaScript array.
* @param {*} value The input variable to test.
* @return {boolean} Whether or not the value is an array.
*/
isArray: Array.isArray || function(value) {
return Object.prototype.toString.call(value) === '[object Array]';
},
toArray: function(obj) {
return utilities.isArray(obj) ? obj : [obj];
/**
* Accepts a value that may or may not be an array. If it is not an array,
* it is returned as the first item in a single-item array.
* @param {*} value The value to convert to an array if it is not.
* @return {Array} The array-ified value.
*/
toArray: function(value) {
return utilities.isArray(value) ? value : [value];
}

@@ -91,0 +114,0 @@ };

{
"name": "autotrack",
"version": "0.6.4",
"version": "0.6.5",
"description": "Automatic + enhanced analytics.js tracking for common user interactions",

@@ -37,21 +37,21 @@ "main": "lib/plugins/autotrack.js",

"devDependencies": {
"browserify": "^12.0.1",
"browserify": "^13.0.0",
"connect": "^3.4.0",
"gulp": "^3.9.0",
"gulp-eslint": "^2.0.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-uglify": "^1.5.1",
"gulp-util": "^3.0.7",
"gulp-webdriver": "^1.0.2",
"lodash": "^3.10.1",
"gulp-webdriver": "^2.0.1",
"lodash": "^4.8.2",
"mocha": "^2.3.4",
"saucelabs": "^1.0.1",
"ngrok": "^2.1.6",
"selenium-server-standalone-jar": "^2.48.2",
"selenium-webdriver": "^2.48.2",
"serve-static": "^1.10.0",
"shelljs": "^0.5.3",
"uglify-js": "^2.6.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"webdriverio": "^3.3.0"
"wdio-mocha-framework": "^0.2.12",
"wdio-sauce-service": "^0.2.2",
"webdriverio": "^4.0.5"
}
}

@@ -397,3 +397,3 @@ # Autotrack [![Build Status](https://travis-ci.org/googleanalytics/autotrack.svg?branch=master)](https://travis-ci.org/googleanalytics/autotrack)

function(newPath, oldPath) {
return true;
return newPath && oldPath;
}

@@ -400,0 +400,0 @@ ```

@@ -18,3 +18,3 @@ /**

var get = require('lodash/object/get');
var get = require('lodash/get');

@@ -41,3 +41,3 @@

ga('set', 'sendHitTask', function(model) {
hitData.push({
window.hitData.push({
hitType: model.get('hitType'),

@@ -44,0 +44,0 @@ page: model.get('page'),

@@ -26,3 +26,3 @@ /**

afterEach(function() {
return browser
browser
.execute(ga.clearHitData)

@@ -38,7 +38,7 @@ .execute(ga.run, 'eventTracker:remove')

it('should provide all plugins', function *() {
it('should provide all plugins', function() {
var gaplugins = (yield browser
var gaplugins = browser
.url('/test/autotrack.html')
.execute(ga.getProvidedPlugins))
.execute(ga.getProvidedPlugins)
.value;

@@ -55,7 +55,6 @@

it('should provide plugins even if sourced before the tracking snippet',
function *() {
function() {
var gaplugins = (yield browser
var gaplugins = browser
.url('/test/autotrack-reorder.html')

@@ -65,3 +64,3 @@ .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')

.execute(ga.run, 'require', 'autotrack')
.execute(ga.getProvidedPlugins))
.execute(ga.getProvidedPlugins)
.value;

@@ -77,5 +76,6 @@

var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'send', 'pageview')
.execute(ga.getHitData)).value;
.execute(ga.getHitData)
.value;

@@ -86,5 +86,5 @@ assert.equal(hitData.length, 1);

it('should work with renaming the global object', function *() {
it('should work with renaming the global object', function() {
var gaplugins = (yield browser
var gaplugins = browser
.url('/test/autotrack-rename.html')

@@ -94,3 +94,3 @@ .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')

.execute(ga.run, 'require', 'autotrack')
.execute(ga.getProvidedPlugins))
.execute(ga.getProvidedPlugins)
.value;

@@ -106,5 +106,6 @@

var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'send', 'pageview')
.execute(ga.getHitData)).value;
.execute(ga.getHitData)
.value;

@@ -117,3 +118,3 @@ assert.equal(hitData.length, 1);

return browser
browser
.url('/test/autotrack.html')

@@ -120,0 +121,0 @@ .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')

@@ -26,13 +26,13 @@ /**

before(function() {
return browser.url('/test/event-tracker.html')
browser.url('/test/event-tracker.html');
});
beforeEach(function() {
return browser
browser
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')
.execute(ga.trackHitData)
})
.execute(ga.trackHitData);
});
afterEach(function () {
return browser
browser
.execute(ga.clearHitData)

@@ -43,8 +43,8 @@ .execute(ga.run, 'eventTracker:remove')

it('should support declarative event binding to DOM elements', function *() {
it('should support declarative event binding to DOM elements', function() {
var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'require', 'eventTracker')
.click('#event-button')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -59,8 +59,8 @@

it('should support only specifying some of the event fields', function *() {
it('should support only specifying some of the event fields', function() {
var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'require', 'eventTracker')
.click('#event-button-some-fields')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -76,8 +76,8 @@

it('should not capture clicks without the category and action fields',
function *() {
function() {
var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'require', 'eventTracker')
.click('#event-button-missing-fields')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -89,8 +89,8 @@

it('should support customizing the attribute prefix', function *() {
it('should support customizing the attribute prefix', function() {
var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'require', 'eventTracker', {attributePrefix: ''})
.click('#event-button-custom-prefix')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -107,3 +107,3 @@

return browser
browser
.execute(ga.run, 'require', 'eventTracker')

@@ -110,0 +110,0 @@ .execute(ga.run, 'send', 'pageview')

@@ -48,3 +48,3 @@ /**

]
}
};

@@ -54,7 +54,7 @@

before(function *() {
browserCaps = (yield browser.session()).value;
before(function() {
browserCaps = browser.session().value;
// Loads the autotrack file since no custom HTML is needed.
yield browser.url('/test/autotrack.html');
browser.url('/test/autotrack.html');
});

@@ -64,4 +64,4 @@

beforeEach(function() {
return browser
.setViewportSize({width:800, height:600}, false)
browser
.setViewportSize({width: 800, height: 600}, false)
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')

@@ -73,3 +73,3 @@ .execute(ga.trackHitData);

afterEach(function () {
return browser
browser
.execute(ga.clearHitData)

@@ -85,3 +85,3 @@ .execute(ga.run, 'mediaQueryTracker:remove')

return browser
browser
.execute(ga.run, 'require', 'mediaQueryTracker', autotrackOpts)

@@ -99,9 +99,11 @@ .waitUntil(ga.trackerDataMatches([

return browser
browser
.execute(ga.run, 'require', 'mediaQueryTracker', autotrackOpts)
.setViewportSize({width:400, height:400}, false)
.setViewportSize({width: 400, height: 400}, false)
.waitUntil(ga.trackerDataMatches([
['dimension1', 'sm'],
['dimension2', 'sm']
]))
]));
browser
.waitUntil(ga.hitDataMatches([

@@ -118,16 +120,16 @@ ['[0].eventCategory', 'Width'],

it('should wait for the timeout to set or send changes', function *() {
it('should wait for the timeout to set or send changes', function() {
if (notSupportedInBrowser()) return;
yield browser
browser
.execute(ga.run, 'require', 'mediaQueryTracker', autotrackOpts)
.setViewportSize({width:400, height:400}, false)
.setViewportSize({width: 400, height: 400}, false);
var timeoutStart = Date.now();
yield browser.waitUntil(ga.trackerDataMatches([
browser.waitUntil(ga.trackerDataMatches([
['dimension1', 'sm'],
['dimension2', 'sm']
]))
.waitUntil(ga.hitDataMatches([
]));
browser.waitUntil(ga.hitDataMatches([
['length', 2]

@@ -141,17 +143,17 @@ ]));

it('should support customizing the timeout period', function *() {
it('should support customizing the timeout period', function() {
if (notSupportedInBrowser()) return;
yield browser
browser
.execute(ga.run, 'require', 'mediaQueryTracker',
Object.assign({}, autotrackOpts, {mediaQueryChangeTimeout: 0}))
.setViewportSize({width:400, height:400}, false)
.setViewportSize({width: 400, height: 400}, false);
var shortTimeoutStart = Date.now();
yield browser.waitUntil(ga.trackerDataMatches([
browser.waitUntil(ga.trackerDataMatches([
['dimension1', 'sm'],
['dimension2', 'sm']
]))
.waitUntil(ga.hitDataMatches([
]));
browser.waitUntil(ga.hitDataMatches([
['length', 2]

@@ -161,3 +163,3 @@ ]));

yield browser
browser
.execute(ga.clearHitData)

@@ -168,12 +170,12 @@ .execute(ga.run, 'mediaQueryTracker:remove')

.execute(ga.trackHitData)
.setViewportSize({width:800, height:600}, false)
.setViewportSize({width: 800, height: 600}, false)
.execute(ga.run, 'require', 'mediaQueryTracker', autotrackOpts)
.setViewportSize({width:400, height:400}, false);
.setViewportSize({width: 400, height: 400}, false);
var longTimeoutStart = Date.now();
yield browser.waitUntil(ga.trackerDataMatches([
browser.waitUntil(ga.trackerDataMatches([
['dimension1', 'sm'],
['dimension2', 'sm']
]))
.waitUntil(ga.hitDataMatches([
]));
browser.waitUntil(ga.hitDataMatches([
['length', 2]

@@ -193,5 +195,5 @@ ]));

return browser
browser
.execute(requireMediaQueryTrackerWithChangeTemplate)
.setViewportSize({width:400, height:400}, false)
.setViewportSize({width: 400, height: 400}, false)
.waitUntil(ga.hitDataMatches([

@@ -206,6 +208,6 @@ ['[0].eventLabel', 'lg:sm'],

return browser
browser
.execute(ga.run, 'require', 'mediaQueryTracker')
.execute(ga.run, 'send', 'pageview')
.waitUntil(ga.hitDataMatches([['[0].devId', 'i5iSjo']]));
.waitUntil(ga.hitDataMatches([['[0].devId', constants.DEV_ID]]));
});

@@ -250,13 +252,6 @@

function isEdge() {
return browserCaps.browserName == 'MicrosoftEdge';
}
function isIE9() {
return browserCaps.browserName == 'internet explorer' &&
browserCaps.version == '9';
}
/**
* @return {boolean} True if the current browser doesn't support all features
* required for these tests.
*/
function notSupportedInBrowser() {

@@ -268,3 +263,5 @@ // TODO(philipwalton): Some capabilities aren't implemented, so we can't test

// IE9 doesn't support matchMedia, so it's not tested.
return isEdge() || isIE9();
return browserCaps.browserName == 'MicrosoftEdge' ||
(browserCaps.browserName == 'internet explorer' &&
browserCaps.version == '9');
}

@@ -20,2 +20,3 @@ /**

var ga = require('./analytics');
var utilities = require('./utilities');
var constants = require('../lib/constants');

@@ -26,23 +27,2 @@

function setupPage() {
return browser.url('/test/outbound-form-tracker.html');
}
function startTracking() {
return browser
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')
.execute(ga.trackHitData)
}
function stopTracking() {
return browser
.execute(unstopFormSubmitEvents)
.execute(ga.clearHitData)
.execute(ga.run, 'outboundFormTracker:remove')
.execute(ga.run, 'remove');
}
before(setupPage);

@@ -53,10 +33,10 @@ beforeEach(startTracking);

it('should send events on outbound form submits', function *() {
it('should send events on outbound form submits', function() {
var hitData = (yield browser
.execute(stopFormSubmitEvents)
.execute(stubBeacon)
var hitData = browser
.execute(utilities.stopFormSubmitEvents)
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundFormTracker')
.click('#submit-1')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -66,14 +46,14 @@

assert.equal(hitData[0].eventAction, 'submit');
assert.equal(hitData[0].eventLabel, 'http://google-analytics.com/collect');
assert.equal(hitData[0].eventLabel, 'https://google-analytics.com/collect');
});
it('should not send events on local form submits', function *() {
it('should not send events on local form submits', function() {
var hitData = (yield browser
.execute(stopFormSubmitEvents)
.execute(stubBeacon)
var hitData = browser
.execute(utilities.stopFormSubmitEvents)
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundFormTracker')
.click('#submit-2')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -85,10 +65,10 @@

it('should work with forms missing the action attribute', function *() {
it('should work with forms missing the action attribute', function() {
var hitData = (yield browser
.execute(stopFormSubmitEvents)
.execute(stubBeacon)
var hitData = browser
.execute(utilities.stopFormSubmitEvents)
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundFormTracker')
.click('#submit-3')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -101,7 +81,7 @@

it('should allow customizing what is considered an outbound form',
function *() {
function() {
var testData = (yield browser
.execute(stopFormSubmitEvents)
.execute(stubBeacon)
var testData = browser
.execute(utilities.stopFormSubmitEvents)
.execute(utilities.stubBeacon)
.execute(requireOutboundFormTrackerWithConditional)

@@ -111,3 +91,3 @@ .click('#submit-1')

.click('#submit-3')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -119,25 +99,25 @@

it('should navigate to the proper outbound location on submit', function *() {
it('should navigate to the proper outbound location on submit', function() {
yield browser
.execute(stubBeacon)
browser
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundFormTracker')
.click('#submit-1')
.waitUntil(urlMatches('http://google-analytics.com/collect'));
.waitUntil(utilities.urlMatches('https://google-analytics.com/collect'));
// Restores the page state.
yield setupPage();
setupPage();
});
it('should navigate to the proper local location on submit', function *() {
it('should navigate to the proper local location on submit', function() {
yield browser
.execute(stubBeacon)
browser
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundFormTracker')
.click('#submit-2')
.waitUntil(urlMatches('/test/blank.html'));
.waitUntil(utilities.urlMatches('/test/blank.html'));
// Restores the page state.
yield setupPage();
setupPage();
});

@@ -147,10 +127,10 @@

it('should stop the event when beacon is not supported and re-emit ' +
'after the hit succeeds or times out', function* () {
'after the hit succeeds or times out', function() {
var hitData = (yield browser
.execute(disableProgramaticFormSubmits)
.execute(stubNoBeacon)
var hitData = browser
.execute(utilities.disableProgramaticFormSubmits)
.execute(utilities.stubNoBeacon)
.execute(ga.run, 'require', 'outboundFormTracker')
.click('#submit-1')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -161,15 +141,15 @@

assert.equal(hitData[0].eventAction, 'submit');
assert.equal(hitData[0].eventLabel, 'http://google-analytics.com/collect');
assert.equal(hitData[0].eventLabel, 'https://google-analytics.com/collect');
// Tests that navigation actually happens
yield setupPage();
yield startTracking();
yield browser
.execute(stubNoBeacon)
setupPage();
startTracking();
browser
.execute(utilities.stubNoBeacon)
.execute(ga.run, 'require', 'outboundFormTracker')
.click('#submit-1')
.waitUntil(urlMatches('http://google-analytics.com/collect'));
.waitUntil(utilities.urlMatches('https://google-analytics.com/collect'));
// Restores the page state.
yield setupPage();
setupPage();

@@ -182,3 +162,3 @@ // TODO(philipwalton): figure out a way to test the hitCallback timing out.

return browser
browser
.execute(ga.run, 'require', 'outboundFormTracker')

@@ -193,2 +173,32 @@ .execute(ga.run, 'send', 'pageview')

/**
* Navigates to the outbound form tracker test page.
*/
function setupPage() {
browser.url('/test/outbound-form-tracker.html');
}
/**
* Initiates the tracker and capturing hit data.
*/
function startTracking() {
browser
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')
.execute(ga.trackHitData);
}
/**
* Stops capturing hit data and remove the plugin and tracker.
*/
function stopTracking() {
browser
.execute(utilities.unstopFormSubmitEvents)
.execute(ga.clearHitData)
.execute(ga.run, 'outboundFormTracker:remove')
.execute(ga.run, 'remove');
}
/**
* Since function objects can't be passed via parameters from server to

@@ -208,44 +218,1 @@ * client, this one-off function must be used to set the value for

}
function urlMatches(expectedUrl) {
return function() {
return browser.url().then(function(result) {
var actualUrl = result.value;
return actualUrl.indexOf(expectedUrl) > -1;
});
}
}
function stopFormSubmitEvents() {
window.__stopFormSubmits__ = function(event) {
event.preventDefault();
};
document.addEventListener('submit', window.__stopFormSubmits__);
}
function unstopFormSubmitEvents() {
document.removeEventListener('submit', window.__stopFormSubmits__);
}
function stubBeacon() {
navigator.sendBeacon = function() {
return true;
};
}
function stubNoBeacon() {
navigator.sendBeacon = undefined;
}
function disableProgramaticFormSubmits() {
for (var i = 0, form; form = document.forms[i]; i++) {
form.submit = function() {};
}
}

@@ -20,2 +20,3 @@ /**

var ga = require('./analytics');
var utilities = require('./utilities');
var constants = require('../lib/constants');

@@ -26,23 +27,2 @@

function setupPage() {
return browser.url('/test/outbound-link-tracker.html');
}
function startTracking() {
return browser
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')
.execute(ga.trackHitData)
}
function stopTracking() {
return browser
.execute(unstopLinkClickEvents)
.execute(ga.clearHitData)
.execute(ga.run, 'outboundLinkTracker:remove')
.execute(ga.run, 'remove');
}
before(setupPage);

@@ -53,10 +33,10 @@ beforeEach(startTracking);

it('should send events on outbound link clicks', function *() {
it('should send events on outbound link clicks', function() {
var hitData = (yield browser
.execute(stopLinkClickEvents)
.execute(stubBeacon)
var hitData = browser
.execute(utilities.stopLinkClickEvents)
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundLinkTracker')
.click('#outbound-link')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -67,14 +47,14 @@

assert.equal(hitData[0].eventAction, 'click');
assert.equal(hitData[0].eventLabel, 'http://google-analytics.com/collect');
assert.equal(hitData[0].eventLabel, 'https://google-analytics.com/collect');
});
it('should not send events on local link clicks', function *() {
it('should not send events on local link clicks', function() {
var hitData = (yield browser
.execute(stopLinkClickEvents)
.execute(stubBeacon)
var hitData = browser
.execute(utilities.stopLinkClickEvents)
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundLinkTracker')
.click('#local-link')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -86,11 +66,11 @@

it('should not send events on non-http(s) protocol links', function*() {
it('should not send events on non-http(s) protocol links', function() {
var hitData = (yield browser
.execute(stopLinkClickEvents)
.execute(stubBeacon)
var hitData = browser
.execute(utilities.stopLinkClickEvents)
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundLinkTracker')
.click('#javascript-protocol')
.click('#file-protocol')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -103,10 +83,10 @@

it('should allow customizing what is considered an outbound link',
function*() {
function() {
var hitData = (yield browser
.execute(stopLinkClickEvents)
.execute(stubBeacon)
var hitData = browser
.execute(utilities.stopLinkClickEvents)
.execute(utilities.stubBeacon)
.execute(requireOutboundLinkTrackerWithConditional)
.click('#outbound-link')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -118,25 +98,25 @@

it('should navigate to the proper location on outbound clicks', function *() {
it('should navigate to the proper location on outbound clicks', function() {
yield browser
.execute(stubBeacon)
browser
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundLinkTracker')
.click('#outbound-link')
.waitUntil(urlMatches('http://google-analytics.com/collect'));
.waitUntil(utilities.urlMatches('https://google-analytics.com/collect'));
// Restores the page state.
yield setupPage();
setupPage();
});
it('should navigate to the proper location on local clicks', function *() {
it('should navigate to the proper location on local clicks', function() {
yield browser
.execute(stubBeacon)
browser
.execute(utilities.stubBeacon)
.execute(ga.run, 'require', 'outboundLinkTracker')
.click('#local-link')
.waitUntil(urlMatches('/test/blank.html'));
.waitUntil(utilities.urlMatches('/test/blank.html'));
// Restores the page state.
yield setupPage();
setupPage();
});

@@ -146,10 +126,10 @@

it('should set the target to "_blank" when beacon is not supported',
function* () {
function() {
var target = (yield browser
.execute(stubNoBeacon)
.execute(stopLinkClickEvents)
var target = browser
.execute(utilities.stubNoBeacon)
.execute(utilities.stopLinkClickEvents)
.execute(ga.run, 'require', 'outboundLinkTracker')
.click('#outbound-link')
.getAttribute('#outbound-link', 'target'));
.getAttribute('#outbound-link', 'target');

@@ -162,3 +142,3 @@ assert.equal('_blank', target);

return browser
browser
.execute(ga.run, 'require', 'outboundLinkTracker')

@@ -173,2 +153,32 @@ .execute(ga.run, 'send', 'pageview')

/**
* Navigates to the outbound link tracker test page.
*/
function setupPage() {
browser.url('/test/outbound-link-tracker.html');
}
/**
* Initiates the tracker and capturing hit data.
*/
function startTracking() {
browser
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')
.execute(ga.trackHitData);
}
/**
* Stops capturing hit data and remove the plugin and tracker.
*/
function stopTracking() {
browser
.execute(utilities.unstopLinkClickEvents)
.execute(ga.clearHitData)
.execute(ga.run, 'outboundLinkTracker:remove')
.execute(ga.run, 'remove');
}
/**
* Since function objects can't be passed via parameters from server to

@@ -185,37 +195,1 @@ * client, this one-off function must be used to set the value for

}
function urlMatches(expectedUrl) {
return function() {
return browser.url().then(function(result) {
var actualUrl = result.value;
return actualUrl.indexOf(expectedUrl) > -1;
});
}
}
function stopLinkClickEvents() {
window.__stopClinkClicks__ = function(event) {
event.preventDefault();
};
document.addEventListener('click', window.__stopClinkClicks__);
}
function unstopLinkClickEvents() {
document.removeEventListener('click', window.__stopClinkClicks__);
}
function stubBeacon() {
navigator.sendBeacon = function() {
return true;
};
}
function stubNoBeacon() {
navigator.sendBeacon = undefined;
}

@@ -28,6 +28,6 @@ /**

before(function *() {
browserCaps = (yield browser.session()).value;
before(function() {
browserCaps = browser.session().value;
yield browser.url('/test/social-tracker.html');
browser.url('/test/social-tracker.html');
});

@@ -37,3 +37,3 @@

beforeEach(function() {
return browser
browser
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')

@@ -45,3 +45,3 @@ .execute(ga.trackHitData);

afterEach(function () {
return browser
browser
.execute(ga.clearHitData)

@@ -53,8 +53,8 @@ .execute(ga.run, 'socialTracker:remove')

it('should support declarative event binding to DOM elements', function *() {
it('should support declarative event binding to DOM elements', function() {
var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'require', 'socialTracker')
.click('#social-button')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -69,8 +69,8 @@

it('should not capture clicks without the network, action, and target fields',
function *() {
function() {
var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'require', 'socialTracker')
.click('#social-button-missing-fields')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -82,8 +82,8 @@

it('should support customizing the attribute prefix', function *() {
it('should support customizing the attribute prefix', function() {
var hitData = (yield browser
var hitData = browser
.execute(ga.run, 'require', 'socialTracker', {attributePrefix: ''})
.click('#social-button-custom-prefix')
.execute(ga.getHitData))
.execute(ga.getHitData)
.value;

@@ -99,17 +99,15 @@

it('should support tweets and follows from the official twitter widgets',
function *() {
function() {
if (notSupportedInBrowser()) return;
yield browser.execute(ga.run, 'require', 'socialTracker')
browser.execute(ga.run, 'require', 'socialTracker');
var tweetFrame = (yield browser
.waitForVisible('iframe.twitter-share-button')
.element('iframe.twitter-share-button')).value;
browser.waitForVisible('iframe.twitter-share-button');
var tweetFrame = browser.element('iframe.twitter-share-button').value;
var followFrame = (yield browser
.waitForVisible('iframe.twitter-follow-button')
.element('iframe.twitter-follow-button')).value;
browser.waitForVisible('iframe.twitter-follow-button');
var followFrame = browser.element('iframe.twitter-follow-button').value;
yield browser
browser
.frame(tweetFrame)

@@ -124,3 +122,3 @@ .click('a')

['[0].socialAction', 'tweet'],
['[0].socialTarget', 'http://example.com'],
['[0].socialTarget', 'https://example.com'],
['[1].socialNetwork', 'Twitter'],

@@ -134,13 +132,13 @@ ['[1].socialAction', 'follow'],

// TODO(philipwalton): figure out why this doesn't work...
// it('should support likes from the official facebook widget', function *() {
// it('should support likes from the official facebook widget', function() {
// var mainWindow = (yield browser
// var mainWindow = browser
// .url('/test/social-tracker-widgets.html')
// .windowHandle()).value;
// .windowHandle().value;
// var likeFrame = (yield browser
// var likeFrame = browser
// .waitForVisible('.fb-like iframe')
// .element('.fb-like iframe')).value;
// .element('.fb-like iframe').value;
// yield browser
// browser
// .frame(likeFrame)

@@ -154,3 +152,3 @@ // .click('form .pluginButtonLabel')

return browser
browser
.execute(ga.run, 'require', 'socialTracker')

@@ -161,20 +159,14 @@ .execute(ga.run, 'send', 'pageview')

});
function isEdge() {
return browserCaps.browserName == 'MicrosoftEdge';
}
function isIE() {
return browserCaps.browserName == 'internet explorer';
}
/**
* @return {boolean} True if the current browser doesn't support all features
* required for these tests.
*/
function notSupportedInBrowser() {
// TODO(philipwalton): IE and Edge are flaky with the tweet button test,
// though they work when manually testing.
return isEdge() || isIE();
return browserCaps.browserName == 'MicrosoftEdge' ||
browserCaps.browserName == 'internet explorer';
}

@@ -29,6 +29,6 @@ /**

before(function *() {
browserCaps = (yield browser.session()).value;
before(function() {
browserCaps = browser.session().value;
yield browser.url('/test/url-change-tracker.html');
browser.url('/test/url-change-tracker.html');
});

@@ -38,3 +38,3 @@

beforeEach(function() {
return browser
browser
.execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto')

@@ -46,3 +46,3 @@ .execute(ga.trackHitData);

afterEach(function () {
return browser
browser
.execute(ga.clearHitData)

@@ -54,11 +54,11 @@ .execute(ga.run, 'urlChangeTracker:remove')

it('should capture URL changes via pushState and popstate', function *() {
it('should capture URL changes via pushState and popstate', function() {
if (notSupportedInBrowser()) return;
yield browser.execute(ga.run, 'require', 'urlChangeTracker');
browser.execute(ga.run, 'require', 'urlChangeTracker');
var fooUrl = (yield browser
var fooUrl = browser
.click('#foo')
.url())
.url()
.value;

@@ -68,5 +68,5 @@

var barUrl = (yield browser
var barUrl = browser
.click('#bar')
.url())
.url()
.value;

@@ -76,5 +76,5 @@

var quxUrl = (yield browser
var quxUrl = browser
.click('#qux')
.url())
.url()
.value;

@@ -84,25 +84,22 @@

var back1Url = (yield browser
.back()
.url())
.value;
// TODO(philipwalton): Safari currently doesn't allow chaining the `back()`
// method, so we have to separate this into two expressions. This can
// probably be reverted in a future version (here and elsewhere).
browser.back();
var back1Url = browser.url().value;
assert.equal(back1Url, baseUrl + '/test/bar.html');
var back2Url = (yield browser
.back()
.url())
.value;
browser.back();
var back2Url = browser.url().value;
assert.equal(back2Url, baseUrl + '/test/foo.html');
var back3Url = (yield browser
.back()
.url())
.value;
browser.back();
var back3Url = browser.url().value;
assert.equal(back3Url, baseUrl + '/test/url-change-tracker.html');
var hitData = (yield browser
.execute(ga.getHitData))
var hitData = browser
.execute(ga.getHitData)
.value;

@@ -125,11 +122,11 @@

it('should update the tracker but not send hits when using replaceState',
function *() {
function() {
if (notSupportedInBrowser()) return;
yield browser.execute(ga.run, 'require', 'urlChangeTracker');
browser.execute(ga.run, 'require', 'urlChangeTracker');
var url = (yield browser
var url = browser
.click('#replace')
.url())
.url()
.value;

@@ -140,5 +137,5 @@

var url = (yield browser
url = browser
.click('#restore')
.url())
.url()
.value;

@@ -149,4 +146,4 @@

var hitData = (yield browser
.execute(ga.getHitData))
var hitData = browser
.execute(ga.getHitData)
.value;

@@ -158,11 +155,11 @@

it('should not capture hash changes', function *() {
it('should not capture hash changes', function() {
if (notSupportedInBrowser()) return;
yield browser.execute(ga.run, 'require', 'urlChangeTracker');
browser.execute(ga.run, 'require', 'urlChangeTracker');
var url = (yield browser
var url = browser
.click('#hash')
.url())
.url()
.value;

@@ -172,11 +169,9 @@

var backUrl = (yield browser
.back()
.url())
.value;
browser.back();
var backUrl = browser.url().value;
assert.equal(backUrl, baseUrl + '/test/url-change-tracker.html');
var hitData = (yield browser
.execute(ga.getHitData))
var hitData = browser
.execute(ga.getHitData)
.value;

@@ -188,11 +183,11 @@

it('should support customizing what is considered a change', function *() {
it('should support customizing what is considered a change', function() {
if (notSupportedInBrowser()) return;
yield browser.execute(requireUrlChangeTrackerTrackerWithConditional);
browser.execute(requireUrlChangeTrackerTrackerWithConditional);
var fooUrl = (yield browser
var fooUrl = browser
.click('#foo')
.url())
.url()
.value;

@@ -202,11 +197,9 @@

var backUrl = (yield browser
.back()
.url())
.value;
browser.back();
var backUrl = browser.url().value;
assert.equal(backUrl, baseUrl + '/test/url-change-tracker.html');
var hitData = (yield browser
.execute(ga.getHitData))
var hitData = browser
.execute(ga.getHitData)
.value;

@@ -220,3 +213,3 @@

return browser
browser
.execute(ga.run, 'require', 'urlChangeTracker')

@@ -237,3 +230,3 @@ .execute(ga.run, 'send', 'pageview')

ga('require', 'urlChangeTracker', {
shouldTrackUrlChange: function(newPath, oldPath) {
shouldTrackUrlChange: function() {
return false;

@@ -245,11 +238,10 @@ }

function isIE9() {
return browserCaps.browserName == 'internet explorer' &&
browserCaps.version == '9';
}
/**
* @return {boolean} True if the current browser doesn't support all features
* required for these tests.
*/
function notSupportedInBrowser() {
// IE9 doesn't support the HTML5 History API.
return isIE9();
return browserCaps.browserName == 'internet explorer' &&
browserCaps.version == '9';
}

@@ -18,74 +18,4 @@ /**

var SauceLabs = require('saucelabs');
// When running on CI, this will be true
var isSauceLabs = process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY;
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
var capabilities = [
{browserName: 'chrome'},
{browserName: 'firefox'}
];
if (isSauceLabs) {
capabilities = [
{
browserName: 'chrome',
platform: 'Windows 10'
},
{
browserName: 'firefox',
platform: 'OS X 10.11'
},
{
browserName: 'safari',
platform: 'OS X 10.11',
version: '9.0',
},
{
browserName: 'safari',
platform: 'OS X 10.8',
version: '6'
},
// TODO(philipwalton) Edge webdriver is too flaky to support at this time.
// Wait for full support and then re-add:
// https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/
// {
// browserName: 'MicrosoftEdge',
// platform: 'Windows 10'
// },
{
browserName: 'internet explorer',
platform: 'Windows 8.1',
version: '11'
},
{
browserName: 'internet explorer',
platform: 'Windows 8',
version: '10'
},
{
browserName: 'internet explorer',
platform: 'Windows 7',
version: '9'
}
];
capabilities.forEach(function(cap) {
cap['name'] = 'analytics.js autotrack tests - ' + cap.browserName +
' - ' + (cap.version || 'latest');
cap['build'] = process.env.TRAVIS_BUILD_NUMBER;
cap['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER;
});
}
exports.config = {
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
// updateJob: true,
//

@@ -111,7 +41,17 @@ // ==================

// ============
// Define your capabilities here. WebdriverIO can run multiple capabilties at the same
// Define your capabilities here. WebdriverIO can run multiple capabilities at the same
// time. Depending on the number of capabilities, WebdriverIO launches several test
// sessions. Within your capabilities you can overwrite the spec and exclude option in
// sessions. Within your capabilities you can overwrite the spec and exclude options in
// order to group specific specs to a specific capability.
//
// First, you can define how many instances should be started at the same time. Let's
// say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have
// set maxInstances to 1, wdio will spawn 3 processes. Therefore, if you have 10 spec
// files and you set maxInstances to 10; all spec files will get tested at the same time
// and 30 processes will get spawned. The property handles how many capabilities
// from the same test should run tests.
//
//
maxInstances: 5,
//
// If you have trouble getting all important capabilities together, check out the

@@ -121,3 +61,3 @@ // Sauce Labs platform configurator - a great tool to configure your capabilities:

//
capabilities: capabilities,
capabilities: getCapabilities(),
//

@@ -129,2 +69,7 @@ // ===================

//
// By default WebdriverIO commands are executed in a synchronous way using
// the wdio-sync package. If you still want to run your tests in an async way
// e.g. using promises you can set the sync option to false.
sync: true,
//
// Level of logging verbosity: silent | verbose | command | data | result | error

@@ -136,11 +81,21 @@ logLevel: 'silent',

//
// Saves a screenshot to a given path if a command fails.
// screenshotPath: './errorShots/',
//
// Set a base URL in order to shorten url command calls. If your url parameter starts
// with "/", the base url gets prepended.
// with "/", then the base url gets prepended.
baseUrl: process.env.BASE_URL || 'http://localhost:8080',
//
// Default timeout for all waitForXXX commands.
waitforTimeout: process.env.CI ? 60000 : 5000,
// Default timeout for all waitFor* commands.
waitforTimeout: 100000,
//
// Default timeout in milliseconds for request
// if Selenium Grid doesn't send response
connectionRetryTimeout: 100000,
//
// Default request retries count
connectionRetryCount: 3,
//
// Initialize the browser instance with a WebdriverIO plugin. The object should have the
// plugin name as key and the desired plugin options as property. Make sure you have
// plugin name as key and the desired plugin options as properties. Make sure you have
// the plugin installed before running any tests. The following plugins are currently

@@ -162,18 +117,22 @@ // available:

//
// Test runner services
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
services: ['sauce'],
user: process.env.SAUCE_USERNAME,
key: process.env.SAUCE_ACCESS_KEY,
//
// Framework you want to run your specs with.
// The following are supported: mocha, jasmine and cucumber
// The following are supported: Mocha, Jasmine, and Cucumber
// see also: http://webdriver.io/guide/testrunner/frameworks.html
//
// Make sure you have the node package for the specific framework installed before running
// any tests. If not please install the following package:
// Mocha: `$ npm install mocha`
// Jasmine: `$ npm install jasmine`
// Cucumber: `$ npm install cucumber`
// Make sure you have the wdio adapter package for the specific framework installed
// before running any tests.
framework: 'mocha',
//
// Test reporter for stdout.
// The following are supported: dot (default), spec and xunit
// The following are supported: dot (default), spec, and xunit
// see also: http://webdriver.io/guide/testrunner/reporters.html
reporter: 'spec',
// reporters: ['dot'],
//

@@ -184,5 +143,4 @@ // Options to be passed to Mocha.

ui: 'bdd',
timeout: 60000
timeout: 100000
},
//

@@ -192,47 +150,125 @@ // =====

// =====
// Run functions before or after the test. If one of them returns with a promise, WebdriverIO
// will wait until that promise got resolved to continue.
// WedriverIO provides several hooks you can use to interfere with the test process in order to enhance
// it and to build services around it. You can either apply a single function or an array of
// methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got
// resolved to continue.
//
// Gets executed before all workers get launched.
onPrepare: function() {
// do something
},
// Gets executed once before all workers get launched.
// onPrepare: function (config, capabilities) {
// },
//
// Gets executed before test execution begins. At this point you will have access to all global
// variables like `browser`. It is the perfect place to define custom commands.
before: function() {
// do something
},
// Gets executed before test execution begins. At this point you can access all global
// variables, such as `browser`. It is the perfect place to define custom commands.
// before: function (capabilities, specs) {
// },
//
// Hook that gets executed before the suite starts
// beforeSuite: function (suite) {
// },
//
// Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
// beforeEach in Mocha)
// beforeHook: function () {
// },
//
// Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling
// afterEach in Mocha)
// afterHook: function () {
// },
//
// Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
// beforeTest: function (test) {
// },
//
// Runs before a WebdriverIO command gets executed.
// beforeCommand: function (commandName, args) {
// },
//
// Runs after a WebdriverIO command gets executed
// afterCommand: function (commandName, args, result, error) {
// },
//
// Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts.
// afterTest: function (test) {
// },
//
// Hook that gets executed after the suite has ended
// afterSuite: function (suite) {
// },
//
// Gets executed after all tests are done. You still have access to all global variables from
// the test.
after: function(failures, sessionId) {
// When runnign in SauceLabs, update the job with the test status.
if (process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY) {
var sauceAccount = new SauceLabs({
username: process.env.SAUCE_USERNAME,
password: process.env.SAUCE_ACCESS_KEY
});
return new Promise(function(resolve, reject) {
var data = {
passed: !failures,
build: process.env.TRAVIS_BUILD_NUMBER
};
sauceAccount.updateJob(sessionId, data, function(err, res) {
if (err) {
reject(err);
}
else {
resolve();
}
});
});
}
},
// after: function (capabilities, specs) {
// },
//
// Gets executed after all workers got shut down and the process is about to exit. It is not
// possible to defer the end of the process using a promise.
onComplete: function() {
// do something
}
};
// onComplete: function(exitCode) {
// }
}
function getCapabilities() {
// When running on CI, this will be true
var isSauceLabs = process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY;
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
var capabilities = [
{browserName: 'chrome'},
{browserName: 'firefox'}
];
if (isSauceLabs) {
capabilities = [
{
browserName: 'chrome',
platform: 'Windows 10'
},
{
browserName: 'firefox',
platform: 'OS X 10.11'
},
{
browserName: 'safari',
platform: 'OS X 10.11',
version: '9.0',
},
{
browserName: 'safari',
platform: 'OS X 10.8',
version: '6'
},
// TODO(philipwalton) Edge webdriver is too flaky to support at this time.
// Wait for full support and then re-add:
// https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/
// {
// browserName: 'MicrosoftEdge',
// platform: 'Windows 10'
// },
{
browserName: 'internet explorer',
platform: 'Windows 8.1',
version: '11'
},
{
browserName: 'internet explorer',
platform: 'Windows 8',
version: '10'
},
{
browserName: 'internet explorer',
platform: 'Windows 7',
version: '9'
}
];
capabilities.forEach(function(cap) {
cap['name'] = 'analytics.js autotrack tests - ' + cap.browserName +
' - ' + (cap.version || 'latest');
cap['build'] = process.env.TRAVIS_BUILD_NUMBER;
});
};
return capabilities;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc