From 682d9d59481beaae775ab11b0a074d634905082c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9as=20=27ScreamZ=27=20Hanss?= Date: Wed, 15 Mar 2017 22:17:46 +0100 Subject: [PATCH] 1.3.0 - Support for timings --- README.md | 11 +++++++++++ dist/vue-analytics.min.js | 2 +- package.json | 2 +- src/AnalyticsPlugin.js | 25 ++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cbfbe55..17c2316 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,17 @@ const myRoute = { */ ``` +### trackTiming (timingCategory, timingVar, timingValue, timingLabel = null) +```javascript +/** + * Track an user timing to measure periods of time. + * + * @param {string} timingCategory - A string for categorizing all user timing variables into logical groups (e.g. 'JS Dependencies'). + * @param {string} timingVar - A string to identify the variable being recorded (e.g. 'load'). + * @param {number} timingValue - The number of milliseconds in elapsed time to report to Google Analytics (e.g. 20). + * @param {string|null} timingLabel - A string that can be used to add flexibility in visualizing user timings in the reports (e.g. 'Google CDN'). + */ +``` ### injectGlobalDimension (dimensionNumber, value) ```javascript /** diff --git a/dist/vue-analytics.min.js b/dist/vue-analytics.min.js index cd84c23..c75694b 100644 --- a/dist/vue-analytics.min.js +++ b/dist/vue-analytics.min.js @@ -1 +1 @@ -module.exports=function(e){function n(a){if(t[a])return t[a].exports;var o=t[a]={exports:{},id:a,loaded:!1};return e[a].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t={};return n.m=e,n.c=t,n.p="",n(0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){"use strict";function a(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t]);return n.default=e,n}function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0});var i=Object.assign||function(e){for(var n=1;n1&&void 0!==arguments[1]?arguments[1]:{};!function(e,n,t,a,o,i,r){e.GoogleAnalyticsObject=o,e[o]=e[o]||function(){(e[o].q=e[o].q||[]).push(arguments)},e[o].l=1*new Date,i=n.createElement(t),r=n.getElementsByTagName(t)[0],i.async=1,i.src=a,r.parentNode.insertBefore(i,r)}(window,document,"script","https://www.google-analytics.com/analytics.js","ga"),n=i({},l.default,n),f.checkMandatoryParams(n),l.default.debug=n.debug,l.default.globalDimensions=n.globalDimensions,l.default.globalMetrics=n.globalMetrics,ga("create",n.trackingId,"auto",{transport:"beacon"}),ga("set","appName",n.appName),ga("set","appVersion",n.appVersion),n.globalDimensions&&n.globalDimensions.forEach(function(e){ga("set","dimension"+e.dimension,e.value)}),n.globalMetrics&&n.globalMetrics.forEach(function(e){ga("set","metric"+e.metric,e.value)}),n.vueRouter&&d(e,n.vueRouter,n.ignoredViews),e.prototype.$analytics=e.prototype.$ua=e.analytics=new u.default},d=function(e,n,t){return t&&(t=t.map(function(e){return e.toLowerCase()})),n.afterEach(function(n){t&&t.indexOf(n.name.toLowerCase())!==-1||e.analytics.trackView(n.meta.analytics||n.name)}),t};n.default={install:g}},function(e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default={debug:!1,globalDimensions:[],globalMetrics:[]}},function(e,n,t){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function o(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i=function(){function e(e,n){for(var t=0;t1&&void 0!==arguments[1]?arguments[1]:null,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;(0,r.logDebug)("Dispatching event",{category:e,action:n,label:t,value:a}),ga("send","event",e,n,t,a)}},{key:"trackException",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];ga("send","exception",{exDescription:e,exFatal:n})}},{key:"injectGlobalDimension",value:function(e,n){if((0,r.logDebug)("Trying dimension Injection...",{dimensionNumber:e,value:n}),c.default.globalDimensions.find(function(n){return n.dimension===e}))throw new Error("VueAnalytics : Dimension already registered");var t={dimension:e,value:n};c.default.globalDimensions.push(t),ga("set","dimension"+t.dimension,t.value),(0,r.logDebug)("Dimension injected")}},{key:"injectGlobalMetric",value:function(e,n){if((0,r.logDebug)("Trying metric Injection...",{metricNumber:e,value:n}),c.default.globalMetrics.find(function(n){return n.metric===e}))throw new Error("VueAnalytics : Metric already registered");var t={metric:e,value:n};c.default.globalMetrics.push(t),ga("set","metric"+t.metric,t.value),(0,r.logDebug)("Metric injected")}},{key:"changeSessionLanguage",value:function(e){(0,r.logDebug)("Changing application localisation & language to "+e),ga("set","language",e)}}]),e}();n.default=u},function(e,n,t){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.cordovaApp=n.checkMandatoryParams=n.logDebug=void 0;var o=t(2),i=a(o);n.logDebug=function(e){if(i.default.debug){var n;(n=console).log.apply(n,["VueAnalytics :"].concat(Array.prototype.slice.call(arguments)))}},n.checkMandatoryParams=function(e){var n=["trackingId","appName","appVersion"];n.forEach(function(n){if(!e[n])throw new Error('VueAnalytics : Please provide a "'+n+'" from the config.')})},n.cordovaApp={bootstrapWindows:function(){window.ActiveXObject=void 0,ga("set","checkProtocolTask",null)}}}]); \ No newline at end of file +module.exports=function(e){function n(a){if(t[a])return t[a].exports;var i=t[a]={exports:{},id:a,loaded:!1};return e[a].call(i.exports,i,i.exports,n),i.loaded=!0,i.exports}var t={};return n.m=e,n.c=t,n.p="",n(0)}([function(e,n,t){e.exports=t(1)},function(e,n,t){"use strict";function a(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t]);return n.default=e,n}function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0});var o=Object.assign||function(e){for(var n=1;n1&&void 0!==arguments[1]?arguments[1]:{};!function(e,n,t,a,i,o,r){e.GoogleAnalyticsObject=i,e[i]=e[i]||function(){(e[i].q=e[i].q||[]).push(arguments)},e[i].l=1*new Date,o=n.createElement(t),r=n.getElementsByTagName(t)[0],o.async=1,o.src=a,r.parentNode.insertBefore(o,r)}(window,document,"script","https://www.google-analytics.com/analytics.js","ga"),n=o({},l.default,n),g.checkMandatoryParams(n),l.default.debug=n.debug,l.default.globalDimensions=n.globalDimensions,l.default.globalMetrics=n.globalMetrics,ga("create",n.trackingId,"auto",{transport:"beacon"}),ga("set","appName",n.appName),ga("set","appVersion",n.appVersion),n.globalDimensions&&n.globalDimensions.forEach(function(e){ga("set","dimension"+e.dimension,e.value)}),n.globalMetrics&&n.globalMetrics.forEach(function(e){ga("set","metric"+e.metric,e.value)}),n.vueRouter&&d(e,n.vueRouter,n.ignoredViews),e.prototype.$analytics=e.prototype.$ua=e.analytics=new c.default},d=function(e,n,t){return t&&(t=t.map(function(e){return e.toLowerCase()})),n.afterEach(function(n){t&&t.indexOf(n.name.toLowerCase())!==-1||e.analytics.trackView(n.meta.analytics||n.name)}),t};n.default={install:f}},function(e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default={debug:!1,globalDimensions:[],globalMetrics:[]}},function(e,n,t){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}function i(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(e,n){for(var t=0;t1&&void 0!==arguments[1]?arguments[1]:null,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;(0,r.logDebug)("Dispatching event",{category:e,action:n,label:t,value:a}),ga("send","event",e,n,t,a)}},{key:"trackException",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];ga("send","exception",{exDescription:e,exFatal:n})}},{key:"trackTiming",value:function(e,n,t){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i={hitType:"timing",timingCategory:e,timingVar:n,timingValue:t};a&&(i.timingLabel=a),(0,r.logDebug)("Dispatching timing",i),ga("send",i)}},{key:"injectGlobalDimension",value:function(e,n){if((0,r.logDebug)("Trying dimension Injection...",{dimensionNumber:e,value:n}),u.default.globalDimensions.find(function(n){return n.dimension===e}))throw new Error("VueAnalytics : Dimension already registered");var t={dimension:e,value:n};u.default.globalDimensions.push(t),ga("set","dimension"+t.dimension,t.value),(0,r.logDebug)("Dimension injected")}},{key:"injectGlobalMetric",value:function(e,n){if((0,r.logDebug)("Trying metric Injection...",{metricNumber:e,value:n}),u.default.globalMetrics.find(function(n){return n.metric===e}))throw new Error("VueAnalytics : Metric already registered");var t={metric:e,value:n};u.default.globalMetrics.push(t),ga("set","metric"+t.metric,t.value),(0,r.logDebug)("Metric injected")}},{key:"changeSessionLanguage",value:function(e){(0,r.logDebug)("Changing application localisation & language to "+e),ga("set","language",e)}}]),e}();n.default=c},function(e,n,t){"use strict";function a(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(n,"__esModule",{value:!0}),n.cordovaApp=n.checkMandatoryParams=n.logDebug=void 0;var i=t(2),o=a(i);n.logDebug=function(e){if(o.default.debug){var n;(n=console).log.apply(n,["VueAnalytics :"].concat(Array.prototype.slice.call(arguments)))}},n.checkMandatoryParams=function(e){var n=["trackingId","appName","appVersion"];n.forEach(function(n){if(!e[n])throw new Error('VueAnalytics : Please provide a "'+n+'" from the config.')})},n.cordovaApp={bootstrapWindows:function(){window.ActiveXObject=void 0,ga("set","checkProtocolTask",null)}}}]); \ No newline at end of file diff --git a/package.json b/package.json index 2c5edff..a78fa6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-ua", - "version": "1.2.3", + "version": "1.3.0", "description": "Help for Google Universal Analytics in Vue application", "main": "./dist/vue-analytics.min.js", "author": "Andréas \"ScreamZ\" Hanss", diff --git a/src/AnalyticsPlugin.js b/src/AnalyticsPlugin.js index 6d7c2e3..419e8f2 100644 --- a/src/AnalyticsPlugin.js +++ b/src/AnalyticsPlugin.js @@ -21,7 +21,7 @@ export default class AnalyticsPlugin { */ trackEvent (category, action = null, label = null, value = null) { // TODO : FieldObject is full syntax, refactor this at one moment - logDebug('Dispatching event', { category, action, label, value}) + logDebug('Dispatching event', { category, action, label, value }) ga('send', 'event', category, action, label, value) } @@ -36,6 +36,29 @@ export default class AnalyticsPlugin { ga('send', 'exception', { 'exDescription': description, 'exFatal': isFatal }); } + /** + * Track an user timing to measure periods of time. + * + * @param {string} timingCategory - A string for categorizing all user timing variables into logical groups (e.g. 'JS Dependencies'). + * @param {string} timingVar - A string to identify the variable being recorded (e.g. 'load'). + * @param {number} timingValue - The number of milliseconds in elapsed time to report to Google Analytics (e.g. 20). + * @param {string|null} timingLabel - A string that can be used to add flexibility in visualizing user timings in the reports (e.g. 'Google CDN'). + */ + trackTiming (timingCategory, timingVar, timingValue, timingLabel = null) { + let conf = { + hitType: 'timing', + timingCategory, + timingVar, + timingValue + } + if (timingLabel) { + conf.timingLabel = timingLabel; + } + + logDebug('Dispatching timing', conf) + ga('send', conf); + } + /** * Inject a new GlobalDimension that will be sent every time. *