From 4256bb8879a26b65e8f854c1b26a1d0990e8a0d5 Mon Sep 17 00:00:00 2001 From: Vinnie Freitas Date: Sun, 18 Mar 2018 23:04:12 -0700 Subject: [PATCH] WEB-1471:ADD: Automatically cast number value for dimension to a string so that GA doesn't throw warnings --- ga-task-manager.js | 2 +- ga-task-manager.js.map | 2 +- lib/index.js | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ga-task-manager.js b/ga-task-manager.js index 3fac412..5e73d67 100644 --- a/ga-task-manager.js +++ b/ga-task-manager.js @@ -1,5 +1,5 @@ (function(){function e(a){var b=this;this.c=a;this.a={};this.b="customTask previewTask checkProtocolTask validationTask checkStorageTask historyImportTask samplerTask buildHitTask sendHitTask timingTask displayFeaturesTask".split(" ");this.addFunctionToTask=this.addFunctionToTask.bind(this);this.removeFunctionFromTask=this.removeFunctionFromTask.bind(this);this.setCustomDimension=this.setCustomDimension.bind(this);this.unsetCustomDimension=this.unsetCustomDimension.bind(this);this.b.forEach(function(c){b.a[c]= [];b.addFunctionToTask(c,"original",a.get(c));b.c.set(c,function(a){b.a[c].forEach(function(b){b.f(a)})})})}e.prototype.addFunctionToTask=function(a,b,c){this.a[a]&&this.a[a].push({name:b,f:c})};e.prototype.removeFunctionFromTask=function(a,b){if(this.a[a]){var c=this.a[a].findIndex(function(a){return a.name===b});-1 {\n this.registry[gaTaskName] = [];\n // Grab a reference to the default function for this task and register it as the first task.\n this.addFunctionToTask(gaTaskName, 'original', tracker.get(gaTaskName));\n\n // Override the GA Tracker's task with our task manager executor.\n this.tracker.set(gaTaskName, (model) => {\n this.registry[gaTaskName].forEach((userTask) => {\n userTask.func(model);\n });\n });\n });\n }\n\n /**\n * Adds a function to be executed at the specified GA Task.\n * @param {string} gaTaskName The name of the GA Task to add the taskFunction to.\n * @param {string} userTaskName An arbitrary name for the task performed by the taskFunction.\n * @param {function(!Model)} taskFunction The function to be added to the execution stack of the GA Task specified in gaTaskName.\n * The GA Model Object (https://developers.google.com/analytics/devguides/collection/analyticsjs/model-object-reference) will be passed to it at time of execution.\n */\n addFunctionToTask(gaTaskName, userTaskName, taskFunction) {\n if (this.registry[gaTaskName]) {\n this.registry[gaTaskName].push({name: userTaskName, func: taskFunction});\n }\n }\n\n /**\n * Removes a function from the specified GA Task by the name given by the user.\n * @param {string} gaTaskName The name of the GA Task to remove the task from.\n * @param {string} userTaskName The arbitrary name for the task given to addFunctionToTask.\n */\n removeFunctionFromTask(gaTaskName, userTaskName) {\n if (this.registry[gaTaskName]) {\n var userTaskIndex = this.registry[gaTaskName].findIndex(function(userTask){\n return userTask.name === userTaskName;\n });\n if (userTaskIndex > -1) {\n this.registry[gaTaskName].splice(userTaskIndex, 1);\n }\n }\n }\n\n /**\n * Adds a function which sets a GA Custom Dimension at the specified GA Task execution time. Defaults to execution on the customTask Task.\n * @param {string} index The index of your dimension as defined in your Google Analytics property settings.\n * @param {string|number|function(): string|number} value Arbitrary string, number or function to set value for the dimension.\n * If a function is given, it will be executed every time at the moment of task execution.\n * Observe size limit for the string value https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#customs\n * @param {string} gaTaskName The name of the GA Task on which to set the Custom Dimension.\n */\n setCustomDimension(index, value, gaTaskName = 'customTask') {\n const userTaskName = 'customDimension' + index;\n this.addFunctionToTask(gaTaskName, userTaskName, function(model){\n let auxValue = value;\n // If user provided a function to set value at execution time, then type check itsreturn value.\n if (typeof value == 'function') {\n auxValue = value();\n const auxType = typeof auxValue;\n if (auxType != 'string' && auxType != 'number') {\n throw new Error('Function ' + value.name + ' must return a string or number. Got ' + auxType + 'instead.');\n }\n }\n // Set the dimension value to be sent to GA.\n model.set('dimension' + index, auxValue);\n });\n }\n\n /**\n * Removes a function added with setCustomDimension.\n * @param {string} index The index of your dimension as defined in your Google Analytics property settings.\n * @param {string} gaTaskName The name of the GA Task to add the taskFunction to.\n */\n unsetCustomDimension(index, gaTaskName = 'customTask') {\n const userTaskName = 'customDimension' + index;\n this.removeFunctionFromTask(gaTaskName, userTaskName);\n }\n\n /**\n * Resets all Tasks of the Tracker to the original function registered at the moment the plugin was required.\n */\n remove() {\n this.gaTaskNames.forEach((gaTaskName) => {\n const originalTaskFunction = this.registry[gaTaskName].find((element) => {\n return element.name == 'original';\n });\n this.tracker.set(gaTaskName, originalTaskFunction);\n });\n }\n}\n\nprovide('gaTaskManager', gaTaskManager);\n","/**\n * Copyright 2016 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Modifications Copyright (C) 2017 Anki, Inc\n */\n\n\nimport {capitalize} from './utilities';\n\n\n/**\n * Provides a plugin for use with analytics.js, accounting for the possibility\n * that the global command queue has been renamed or not yet defined.\n * @param {string} pluginName The plugin name identifier.\n * @param {Function} pluginConstructor The plugin constructor function.\n */\nexport default function provide(pluginName, pluginConstructor) {\n const gaAlias = window.GoogleAnalyticsObject || 'ga';\n window[gaAlias] = window[gaAlias] || function(...args) {\n (window[gaAlias].q = window[gaAlias].q || []).push(args);\n };\n\n // Formally provides the plugin for use with analytics.js.\n window[gaAlias]('provide', pluginName, pluginConstructor);\n\n // Registers the plugin on the global gaplugins object.\n window.gaplugins = window.gaplugins || {};\n window.gaplugins[capitalize(pluginName)] = pluginConstructor;\n}\n","/**\n * Copyright 2016 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Modifications Copyright (C) 2018 Anki, Inc.\n */\n\n/**\n * A small shim of Object.assign that aims for brevity over spec-compliant\n * handling all the edge cases.\n * @param {!Object} target The target object to assign to.\n * @param {...?Object} sources Additional objects who properties should be\n * assigned to target. Non-objects are converted to objects.\n * @return {!Object} The modified target object.\n */\nexport const assign = Object.assign || function(target, ...sources) {\n for (let i = 0, len = sources.length; i < len; i++) {\n const source = Object(sources[i]);\n for (let key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n return target;\n};\n\n\n/**\n * Capitalizes the first letter of a string.\n * @param {string} str The input string.\n * @return {string} The capitalized string\n */\nexport function capitalize(str) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"]} \ No newline at end of file +{"version":3,"sources":["lib/index.js","lib/provide.js","lib/utilities.js"],"names":["constructor","gaTaskManager","tracker","registry","gaTaskNames","addFunctionToTask","bind","removeFunctionFromTask","setCustomDimension","unsetCustomDimension","forEach","gaTaskName","get","set","model","userTask","func","userTaskName","taskFunction","push","name","userTaskIndex","findIndex","splice","index","value","auxValue","auxType","Error","toString","remove","originalTaskFunction","find","element","provide","pluginName","pluginConstructor","gaAlias","window","GoogleAnalyticsObject","q","args","gaplugins","charAt","toUpperCase","slice"],"mappings":"A,YAWEA,QALIC,EAKO,CAACC,CAAD,CAAU,CAAA,IAAA,EAAA,IACnB,KAAAA,EAAA,CAAeA,CACf,KAAAC,EAAA,CAAgB,EAEhB,KAAAC,EAAA,CAAmB,gKAAA,MAAA,CAAA,GAAA,CAenB,KAAAC,kBAAA,CAAyB,IAAAA,kBAAAC,KAAA,CAA4B,IAA5B,CACzB,KAAAC,uBAAA,CAA8B,IAAAA,uBAAAD,KAAA,CAAiC,IAAjC,CAC9B,KAAAE,mBAAA,CAA0B,IAAAA,mBAAAF,KAAA,CAA6B,IAA7B,CAC1B,KAAAG,qBAAA,CAA4B,I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MAAA,CAAOD,CAAP,CAAlB,EAAqC,QAAA,CAAS,CAAT,CAAkB,CAAT,IAAA,IAAA,EAAA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,SAAA,OAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,SAAA,CAAA,CAAA,CAC5ClB,EAACmB,MAAA,CAAOD,CAAP,CAAAG,EAADrB,CAAqBmB,MAAA,CAAOD,CAAP,CAAAG,EAArBrB,EAA0C,EAA1CA,MAAA,CADqDsB,CACrD,CADqD,CAKvDH,OAAA,CAAOD,CAAP,CAAA,CAAgB,SAAhB,CAA2BF,CAA3B,CAAuCC,CAAvC,CAGAE,OAAAI,UAAA,CAAmBJ,MAAAI,UAAnB,EAAuC,EACvCJ,OAAAI,UAAA,CAA4BP,CCMrBQ,OAAA,CAAW,CAAX,CAAAC,YAAA,EDNP,CAA4BT,CCMSU,MAAA,CAAU,CAAV,CDNrC,CAAA,CAA2CT,CAXkB,CAA/DF,CDsGA,CAAQ,eAAR,CAAyBjC,CAAzB","file":"","sourcesContent":["import provide from './provide';\n\n/**\n * Class for the `ga-task-manager` analytics.js plugin.\n * @implements {GATaskManagerPublicInterface}\n */\nclass gaTaskManager {\n /**\n * Registers declarative event tracking.\n * @param {!Tracker} tracker Passed internally by analytics.js\n */\n constructor(tracker) {\n this.tracker = tracker;\n this.registry = {};\n // @see https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks\n this.gaTaskNames = [\n 'customTask',\n 'previewTask',\n 'checkProtocolTask',\n 'validationTask',\n 'checkStorageTask',\n 'historyImportTask',\n 'samplerTask',\n 'buildHitTask',\n 'sendHitTask',\n 'timingTask',\n 'displayFeaturesTask'\n ];\n\n // Bind methods.\n this.addFunctionToTask = this.addFunctionToTask.bind(this);\n this.removeFunctionFromTask = this.removeFunctionFromTask.bind(this);\n this.setCustomDimension = this.setCustomDimension.bind(this);\n this.unsetCustomDimension = this.unsetCustomDimension.bind(this);\n\n this.gaTaskNames.forEach((gaTaskName) => {\n this.registry[gaTaskName] = [];\n // Grab a reference to the default function for this task and register it as the first task.\n this.addFunctionToTask(gaTaskName, 'original', tracker.get(gaTaskName));\n\n // Override the GA Tracker's task with our task manager executor.\n this.tracker.set(gaTaskName, (model) => {\n this.registry[gaTaskName].forEach((userTask) => {\n userTask.func(model);\n });\n });\n });\n }\n\n /**\n * Adds a function to be executed at the specified GA Task.\n * @param {string} gaTaskName The name of the GA Task to add the taskFunction to.\n * @param {string} userTaskName An arbitrary name for the task performed by the taskFunction.\n * @param {function(!Model)} taskFunction The function to be added to the execution stack of the GA Task specified in gaTaskName.\n * The GA Model Object (https://developers.google.com/analytics/devguides/collection/analyticsjs/model-object-reference) will be passed to it at time of execution.\n */\n addFunctionToTask(gaTaskName, userTaskName, taskFunction) {\n if (this.registry[gaTaskName]) {\n this.registry[gaTaskName].push({name: userTaskName, func: taskFunction});\n }\n }\n\n /**\n * Removes a function from the specified GA Task by the name given by the user.\n * @param {string} gaTaskName The name of the GA Task to remove the task from.\n * @param {string} userTaskName The arbitrary name for the task given to addFunctionToTask.\n */\n removeFunctionFromTask(gaTaskName, userTaskName) {\n if (this.registry[gaTaskName]) {\n var userTaskIndex = this.registry[gaTaskName].findIndex(function(userTask){\n return userTask.name === userTaskName;\n });\n if (userTaskIndex > -1) {\n this.registry[gaTaskName].splice(userTaskIndex, 1);\n }\n }\n }\n\n /**\n * Adds a function which sets a GA Custom Dimension at the specified GA Task execution time. Defaults to execution on the customTask Task.\n * @param {string} index The index of your dimension as defined in your Google Analytics property settings.\n * @param {string|number|function(): string|number} value Arbitrary string, number or function to set value for the dimension.\n * If a function is given, it will be executed every time at the moment of task execution.\n * If a number is given, it will be cast automatically to a string by calling Number.toString() method.\n * Observe size limit for the string value https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#customs\n * @param {string} gaTaskName The name of the GA Task on which to set the Custom Dimension.\n */\n setCustomDimension(index, value, gaTaskName = 'customTask') {\n const userTaskName = 'customDimension' + index;\n this.addFunctionToTask(gaTaskName, userTaskName, function(model){\n let auxValue = value;\n // If user provided a function to set value at execution time, then type check itsreturn value.\n if (typeof value == 'function') {\n auxValue = value();\n const auxType = typeof auxValue;\n if (auxType != 'string' && auxType != 'number') {\n throw new Error('Function ' + value.name + ' must return a string or number. Got ' + auxType + 'instead.');\n }\n }\n\n if (typeof auxValue === 'number') auxValue = auxValue.toString();\n\n // Set the dimension value to be sent to GA.\n model.set('dimension' + index, auxValue);\n });\n }\n\n /**\n * Removes a function added with setCustomDimension.\n * @param {string} index The index of your dimension as defined in your Google Analytics property settings.\n * @param {string} gaTaskName The name of the GA Task to add the taskFunction to.\n */\n unsetCustomDimension(index, gaTaskName = 'customTask') {\n const userTaskName = 'customDimension' + index;\n this.removeFunctionFromTask(gaTaskName, userTaskName);\n }\n\n /**\n * Resets all Tasks of the Tracker to the original function registered at the moment the plugin was required.\n */\n remove() {\n this.gaTaskNames.forEach((gaTaskName) => {\n const originalTaskFunction = this.registry[gaTaskName].find((element) => {\n return element.name == 'original';\n });\n this.tracker.set(gaTaskName, originalTaskFunction);\n });\n }\n}\n\nprovide('gaTaskManager', gaTaskManager);\n","/**\n * Copyright 2016 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Modifications Copyright (C) 2017 Anki, Inc\n */\n\n\nimport {capitalize} from './utilities';\n\n\n/**\n * Provides a plugin for use with analytics.js, accounting for the possibility\n * that the global command queue has been renamed or not yet defined.\n * @param {string} pluginName The plugin name identifier.\n * @param {Function} pluginConstructor The plugin constructor function.\n */\nexport default function provide(pluginName, pluginConstructor) {\n const gaAlias = window.GoogleAnalyticsObject || 'ga';\n window[gaAlias] = window[gaAlias] || function(...args) {\n (window[gaAlias].q = window[gaAlias].q || []).push(args);\n };\n\n // Formally provides the plugin for use with analytics.js.\n window[gaAlias]('provide', pluginName, pluginConstructor);\n\n // Registers the plugin on the global gaplugins object.\n window.gaplugins = window.gaplugins || {};\n window.gaplugins[capitalize(pluginName)] = pluginConstructor;\n}\n","/**\n * Copyright 2016 Google Inc. All Rights Reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * Modifications Copyright (C) 2018 Anki, Inc.\n */\n\n/**\n * A small shim of Object.assign that aims for brevity over spec-compliant\n * handling all the edge cases.\n * @param {!Object} target The target object to assign to.\n * @param {...?Object} sources Additional objects who properties should be\n * assigned to target. Non-objects are converted to objects.\n * @return {!Object} The modified target object.\n */\nexport const assign = Object.assign || function(target, ...sources) {\n for (let i = 0, len = sources.length; i < len; i++) {\n const source = Object(sources[i]);\n for (let key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n return target;\n};\n\n\n/**\n * Capitalizes the first letter of a string.\n * @param {string} str The input string.\n * @return {string} The capitalized string\n */\nexport function capitalize(str) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n"]} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index eb3d68b..0acf17b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -81,6 +81,7 @@ class gaTaskManager { * @param {string} index The index of your dimension as defined in your Google Analytics property settings. * @param {string|number|function(): string|number} value Arbitrary string, number or function to set value for the dimension. * If a function is given, it will be executed every time at the moment of task execution. + * If a number is given, it will be cast automatically to a string by calling Number.toString() method. * Observe size limit for the string value https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#customs * @param {string} gaTaskName The name of the GA Task on which to set the Custom Dimension. */ @@ -96,6 +97,9 @@ class gaTaskManager { throw new Error('Function ' + value.name + ' must return a string or number. Got ' + auxType + 'instead.'); } } + + if (typeof auxValue === 'number') auxValue = auxValue.toString(); + // Set the dimension value to be sent to GA. model.set('dimension' + index, auxValue); });