From 5758c1866139d8ca8dffcfdbb83d5348ec7d4919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Cl=C3=A9ment?= Date: Fri, 4 Feb 2022 09:28:27 +0100 Subject: [PATCH] Add customClientId parameter --- .gitignore | 3 +- dist/vue-gtag.esm.js | 607 +++++++++++++++++++++++++++++++++ dist/vue-gtag.js | 631 ++++++++++++++++++++++++++++++++++ dist/vue-gtag.umd.js | 635 +++++++++++++++++++++++++++++++++++ dist/vue-gtag.umd.min.js | 2 + dist/vue-gtag.umd.min.js.map | 1 + src/add-configuration.js | 4 + src/options.js | 1 + 8 files changed, 1882 insertions(+), 2 deletions(-) create mode 100644 dist/vue-gtag.esm.js create mode 100644 dist/vue-gtag.js create mode 100644 dist/vue-gtag.umd.js create mode 100644 dist/vue-gtag.umd.min.js create mode 100644 dist/vue-gtag.umd.min.js.map diff --git a/.gitignore b/.gitignore index 71e8204..a135df8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ -dist/ node_modules/ .DS_Store npm-debug.log yarn-error.log -coverage/ \ No newline at end of file +coverage/ diff --git a/dist/vue-gtag.esm.js b/dist/vue-gtag.esm.js new file mode 100644 index 0000000..f676c1a --- /dev/null +++ b/dist/vue-gtag.esm.js @@ -0,0 +1,607 @@ +import Vue from 'vue'; + +function _typeof(obj) { + "@babel/helpers - typeof"; + + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + + if (i % 2) { + ownKeys(Object(source), true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + } + + return target; +} + +var load = function load(url) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return new Promise(function (resolve, reject) { + if (typeof document === "undefined") { + return; + } + + var head = document.head || document.getElementsByTagName("head")[0]; + var script = document.createElement("script"); + script.async = true; + script.src = url; + script.defer = options.defer; + + if (options.preconnectOrigin) { + var link = document.createElement("link"); + link.href = options.preconnectOrigin; + link.rel = "preconnect"; + head.appendChild(link); + } + + head.appendChild(script); + script.onload = resolve; + script.onerror = reject; + }); +}; +var isFn = function isFn(fn) { + return typeof fn === "function"; +}; +var isObject = function isObject(item) { + return item && _typeof(item) === "object" && !Array.isArray(item); +}; +var mergeDeep = function mergeDeep(target) { + for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + sources[_key - 1] = arguments[_key]; + } + + if (!sources.length) { + return target; + } + + var source = sources.shift(); + + if (!isObject(target) || !isObject(source)) { + return; + } + + for (var key in source) { + if (isObject(source[key])) { + if (!target[key]) { + Object.assign(target, _defineProperty({}, key, {})); + } + + mergeDeep(target[key], source[key]); + } else { + Object.assign(target, _defineProperty({}, key, source[key])); + } + } + + return mergeDeep.apply(void 0, [target].concat(sources)); +}; +var isBrowser = function isBrowser() { + if (typeof window === "undefined" || typeof document === "undefined") { + return false; + } + + return true; +}; +var warn = function warn(text) { + var shouldLog = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + + if (!isBrowser() || process.env.NODE_ENV === "production") { + return; + } + + if (!shouldLog) { + return; + } + + console.warn("[vue-gtag] ".concat(text)); +}; +var validateScreenviewShape = function validateScreenviewShape() { + var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + warn("Missing \"appName\" property inside the plugin options.", obj.app_name == null); + warn("Missing \"name\" property in the route.", obj.screen_name == null); + return obj; +}; +function getPathWithBase() { + var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; + var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; + var pathAsArray = path.split("/"); + var baseAsArray = base.split("/"); + + if (pathAsArray[0] === "" && base[base.length - 1] === "/") { + pathAsArray.shift(); + } + + return baseAsArray.join("/") + pathAsArray.join("/"); +} + +var getDefaultParams = function getDefaultParams() { + return { + bootstrap: true, + onReady: null, + onError: null, + onBeforeTrack: null, + onAfterTrack: null, + pageTrackerTemplate: null, + customResourceURL: "https://www.googletagmanager.com/gtag/js", + customPreconnectOrigin: "https://www.googletagmanager.com", + deferScriptLoad: false, + pageTrackerExcludedRoutes: [], + pageTrackerEnabled: true, + enabled: true, + disableScriptLoad: false, + pageTrackerScreenviewEnabled: false, + appName: null, + pageTrackerUseFullPath: false, + pageTrackerPrependBase: true, + pageTrackerSkipSamePath: true, + globalDataLayerName: "dataLayer", + globalObjectName: "gtag", + defaultGroupName: "default", + includes: null, + config: { + id: null, + params: { + send_page_view: false + } + }, + customClientId: "" + }; +}; +var params = {}; +var setOptions = function setOptions() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var defaultParams = getDefaultParams(); + params = mergeDeep(defaultParams, options); +}; +var getOptions = function getOptions() { + return params; +}; + +var query = (function () { + var _window; + + if (!isBrowser()) { + return; + } + + var _getOptions = getOptions(), + globalObjectName = _getOptions.globalObjectName; + + (_window = window)[globalObjectName].apply(_window, arguments); +}); + +var config = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + query.apply(void 0, ["config", config.id].concat(args)); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + query.apply(void 0, ["config", domain.id].concat(args)); + }); + } +}); + +var assignGlobalProperty = function assignGlobalProperty(id, value) { + if (!isBrowser()) { + return; + } + + window["ga-disable-".concat(id)] = value; +}; + +var disable = (function () { + var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + assignGlobalProperty(config.id, value); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + return assignGlobalProperty(domain.id, value); + }); + } +}); + +var optOut = (function () { + disable(true); +}); + +var optIn = (function () { + disable(false); +}); + +var router; +var setRouter = function setRouter(instance) { + router = instance; +}; +var getRouter = function getRouter() { + return router; +}; + +var event = (function (name) { + var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var _getOptions = getOptions(), + includes = _getOptions.includes, + defaultGroupName = _getOptions.defaultGroupName; + + if (params.send_to == null && Array.isArray(includes) && includes.length) { + params.send_to = includes.map(function (domain) { + return domain.id; + }).concat(defaultGroupName); + } + + query("event", name, params); +}); + +var pageview = (function (param) { + if (!isBrowser()) { + return; + } + + var template; + + if (typeof param === "string") { + template = { + page_path: param + }; + } else if (param.path || param.fullPath) { + var _getOptions = getOptions(), + useFullPath = _getOptions.pageTrackerUseFullPath, + useBase = _getOptions.pageTrackerPrependBase; + + var router = getRouter(); + var base = router && router.options.base; + var path = useFullPath ? param.fullPath : param.path; + template = _objectSpread2(_objectSpread2({}, param.name && { + page_title: param.name + }), {}, { + page_path: useBase ? getPathWithBase(path, base) : path + }); + } else { + template = param; + } + + if (template.page_location == null) { + template.page_location = window.location.href; + } + + if (template.send_page_view == null) { + template.send_page_view = true; + } + + event("page_view", template); +}); + +var screenview = (function (param) { + var _getOptions = getOptions(), + appName = _getOptions.appName; + + if (!param) { + return; + } + + var template; + + if (typeof param === "string") { + template = { + screen_name: param + }; + } else { + template = param; + } + + template.app_name = template.app_name || appName; + event("screen_view", template); +}); + +var exception = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + event.apply(void 0, ["exception"].concat(args)); +}); + +var linker = (function (params) { + config("linker", params); +}); + +var time = (function (params) { + event("timing_complete", params); +}); + +var set = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + query.apply(void 0, ["set"].concat(args)); +}); + +var refund = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + event.apply(void 0, ["refund"].concat(args)); +}); + +var purchase = (function (params) { + event("purchase", params); +}); + +var customMap = (function (map) { + config({ + custom_map: map + }); +}); + +var api = /*#__PURE__*/Object.freeze({ + __proto__: null, + query: query, + config: config, + optOut: optOut, + optIn: optIn, + pageview: pageview, + screenview: screenview, + exception: exception, + linker: linker, + time: time, + set: set, + refund: refund, + purchase: purchase, + customMap: customMap, + event: event +}); + +var attachApi = function attachApi(Vue) { + return Vue.$gtag = Vue.prototype.$gtag = api; +}; + +var registerGlobals = (function () { + if (!isBrowser()) { + return; + } + + var _getOptions = getOptions(), + enabled = _getOptions.enabled, + globalObjectName = _getOptions.globalObjectName, + globalDataLayerName = _getOptions.globalDataLayerName; + + if (window[globalObjectName] == null) { + window[globalDataLayerName] = window[globalDataLayerName] || []; + + window[globalObjectName] = function () { + window[globalDataLayerName].push(arguments); + }; + } + + window[globalObjectName]("js", new Date()); + + if (!enabled) { + optOut(); + } + + return window[globalObjectName]; +}); + +var mergeDefaultParams = function mergeDefaultParams(params) { + return _objectSpread2({ + send_page_view: false + }, params); +}; + +var addConfiguration = (function () { + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + query("config", config.id, mergeDefaultParams(config.params)); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + query("config", domain.id, mergeDefaultParams(domain.params)); + }); + } + + if (config.customClientId) { + query("set", { + client_id: config.custom_client_id + }); + } +}); + +var track = (function () { + var to = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var _getOptions = getOptions(), + appName = _getOptions.appName, + proxy = _getOptions.pageTrackerTemplate, + useScreenview = _getOptions.pageTrackerScreenviewEnabled, + skipSamePath = _getOptions.pageTrackerSkipSamePath; + + if (skipSamePath && to.path === from.path) { + return; + } + + var template = to; + + if (isFn(proxy)) { + template = proxy(to, from); + } else if (useScreenview) { + template = validateScreenviewShape({ + app_name: appName, + screen_name: to.name + }); + } + + if (useScreenview) { + screenview(template); + return; + } + + pageview(template); +}); + +var isRouteExcluded = function isRouteExcluded(route) { + var _getOptions = getOptions(), + routes = _getOptions.pageTrackerExcludedRoutes; + + return routes.includes(route.path) || routes.includes(route.name); +}; + +var addRoutesTracker = (function () { + var _getOptions2 = getOptions(), + onBeforeTrack = _getOptions2.onBeforeTrack, + onAfterTrack = _getOptions2.onAfterTrack; + + var router = getRouter(); + router.onReady(function () { + Vue.nextTick().then(function () { + var currentRoute = router.currentRoute; + addConfiguration(); + + if (isRouteExcluded(currentRoute)) { + return; + } + + track(currentRoute); + }); + router.afterEach(function (to, from) { + Vue.nextTick().then(function () { + if (isRouteExcluded(to)) { + return; + } + + if (isFn(onBeforeTrack)) { + onBeforeTrack(to, from); + } + + track(to, from); + + if (isFn(onAfterTrack)) { + onAfterTrack(to, from); + } + }); + }); + }); +}); + +var bootstrap = (function () { + var _getOptions = getOptions(), + onReady = _getOptions.onReady, + onError = _getOptions.onError, + globalObjectName = _getOptions.globalObjectName, + globalDataLayerName = _getOptions.globalDataLayerName, + config = _getOptions.config, + customResourceURL = _getOptions.customResourceURL, + customPreconnectOrigin = _getOptions.customPreconnectOrigin, + deferScriptLoad = _getOptions.deferScriptLoad, + pageTrackerEnabled = _getOptions.pageTrackerEnabled, + disableScriptLoad = _getOptions.disableScriptLoad; + + var isPageTrackerEnabled = Boolean(pageTrackerEnabled && getRouter()); + registerGlobals(); + + if (isPageTrackerEnabled) { + addRoutesTracker(); + } else { + addConfiguration(); + } + + if (disableScriptLoad) { + return; + } + + return load("".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName), { + preconnectOrigin: customPreconnectOrigin, + defer: deferScriptLoad + }).then(function () { + if (onReady) { + onReady(window[globalObjectName]); + } + }).catch(function (error) { + if (onError) { + onError(error); + } + + return error; + }); +}); + +var install = function install(Vue) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var router = arguments.length > 2 ? arguments[2] : undefined; + attachApi(Vue); + setOptions(options); + setRouter(router); + + if (getOptions().bootstrap) { + bootstrap(); + } +}; + +export default install; +export { addRoutesTracker, bootstrap, config, customMap, event, exception, install, linker, optIn, optOut, pageview, purchase, query, refund, screenview, set, setOptions, setRouter, time }; diff --git a/dist/vue-gtag.js b/dist/vue-gtag.js new file mode 100644 index 0000000..c7fa4c1 --- /dev/null +++ b/dist/vue-gtag.js @@ -0,0 +1,631 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var Vue = _interopDefault(require('vue')); + +function _typeof(obj) { + "@babel/helpers - typeof"; + + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; +} + +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + + if (i % 2) { + ownKeys(Object(source), true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + } + + return target; +} + +var load = function load(url) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return new Promise(function (resolve, reject) { + if (typeof document === "undefined") { + return; + } + + var head = document.head || document.getElementsByTagName("head")[0]; + var script = document.createElement("script"); + script.async = true; + script.src = url; + script.defer = options.defer; + + if (options.preconnectOrigin) { + var link = document.createElement("link"); + link.href = options.preconnectOrigin; + link.rel = "preconnect"; + head.appendChild(link); + } + + head.appendChild(script); + script.onload = resolve; + script.onerror = reject; + }); +}; +var isFn = function isFn(fn) { + return typeof fn === "function"; +}; +var isObject = function isObject(item) { + return item && _typeof(item) === "object" && !Array.isArray(item); +}; +var mergeDeep = function mergeDeep(target) { + for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + sources[_key - 1] = arguments[_key]; + } + + if (!sources.length) { + return target; + } + + var source = sources.shift(); + + if (!isObject(target) || !isObject(source)) { + return; + } + + for (var key in source) { + if (isObject(source[key])) { + if (!target[key]) { + Object.assign(target, _defineProperty({}, key, {})); + } + + mergeDeep(target[key], source[key]); + } else { + Object.assign(target, _defineProperty({}, key, source[key])); + } + } + + return mergeDeep.apply(void 0, [target].concat(sources)); +}; +var isBrowser = function isBrowser() { + if (typeof window === "undefined" || typeof document === "undefined") { + return false; + } + + return true; +}; +var warn = function warn(text) { + var shouldLog = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + + if (!isBrowser() || process.env.NODE_ENV === "production") { + return; + } + + if (!shouldLog) { + return; + } + + console.warn("[vue-gtag] ".concat(text)); +}; +var validateScreenviewShape = function validateScreenviewShape() { + var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + warn("Missing \"appName\" property inside the plugin options.", obj.app_name == null); + warn("Missing \"name\" property in the route.", obj.screen_name == null); + return obj; +}; +function getPathWithBase() { + var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; + var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; + var pathAsArray = path.split("/"); + var baseAsArray = base.split("/"); + + if (pathAsArray[0] === "" && base[base.length - 1] === "/") { + pathAsArray.shift(); + } + + return baseAsArray.join("/") + pathAsArray.join("/"); +} + +var getDefaultParams = function getDefaultParams() { + return { + bootstrap: true, + onReady: null, + onError: null, + onBeforeTrack: null, + onAfterTrack: null, + pageTrackerTemplate: null, + customResourceURL: "https://www.googletagmanager.com/gtag/js", + customPreconnectOrigin: "https://www.googletagmanager.com", + deferScriptLoad: false, + pageTrackerExcludedRoutes: [], + pageTrackerEnabled: true, + enabled: true, + disableScriptLoad: false, + pageTrackerScreenviewEnabled: false, + appName: null, + pageTrackerUseFullPath: false, + pageTrackerPrependBase: true, + pageTrackerSkipSamePath: true, + globalDataLayerName: "dataLayer", + globalObjectName: "gtag", + defaultGroupName: "default", + includes: null, + config: { + id: null, + params: { + send_page_view: false + } + }, + customClientId: "" + }; +}; +var params = {}; +var setOptions = function setOptions() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var defaultParams = getDefaultParams(); + params = mergeDeep(defaultParams, options); +}; +var getOptions = function getOptions() { + return params; +}; + +var query = (function () { + var _window; + + if (!isBrowser()) { + return; + } + + var _getOptions = getOptions(), + globalObjectName = _getOptions.globalObjectName; + + (_window = window)[globalObjectName].apply(_window, arguments); +}); + +var config = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + query.apply(void 0, ["config", config.id].concat(args)); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + query.apply(void 0, ["config", domain.id].concat(args)); + }); + } +}); + +var assignGlobalProperty = function assignGlobalProperty(id, value) { + if (!isBrowser()) { + return; + } + + window["ga-disable-".concat(id)] = value; +}; + +var disable = (function () { + var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + assignGlobalProperty(config.id, value); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + return assignGlobalProperty(domain.id, value); + }); + } +}); + +var optOut = (function () { + disable(true); +}); + +var optIn = (function () { + disable(false); +}); + +var router; +var setRouter = function setRouter(instance) { + router = instance; +}; +var getRouter = function getRouter() { + return router; +}; + +var event = (function (name) { + var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var _getOptions = getOptions(), + includes = _getOptions.includes, + defaultGroupName = _getOptions.defaultGroupName; + + if (params.send_to == null && Array.isArray(includes) && includes.length) { + params.send_to = includes.map(function (domain) { + return domain.id; + }).concat(defaultGroupName); + } + + query("event", name, params); +}); + +var pageview = (function (param) { + if (!isBrowser()) { + return; + } + + var template; + + if (typeof param === "string") { + template = { + page_path: param + }; + } else if (param.path || param.fullPath) { + var _getOptions = getOptions(), + useFullPath = _getOptions.pageTrackerUseFullPath, + useBase = _getOptions.pageTrackerPrependBase; + + var router = getRouter(); + var base = router && router.options.base; + var path = useFullPath ? param.fullPath : param.path; + template = _objectSpread2(_objectSpread2({}, param.name && { + page_title: param.name + }), {}, { + page_path: useBase ? getPathWithBase(path, base) : path + }); + } else { + template = param; + } + + if (template.page_location == null) { + template.page_location = window.location.href; + } + + if (template.send_page_view == null) { + template.send_page_view = true; + } + + event("page_view", template); +}); + +var screenview = (function (param) { + var _getOptions = getOptions(), + appName = _getOptions.appName; + + if (!param) { + return; + } + + var template; + + if (typeof param === "string") { + template = { + screen_name: param + }; + } else { + template = param; + } + + template.app_name = template.app_name || appName; + event("screen_view", template); +}); + +var exception = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + event.apply(void 0, ["exception"].concat(args)); +}); + +var linker = (function (params) { + config("linker", params); +}); + +var time = (function (params) { + event("timing_complete", params); +}); + +var set = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + query.apply(void 0, ["set"].concat(args)); +}); + +var refund = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + event.apply(void 0, ["refund"].concat(args)); +}); + +var purchase = (function (params) { + event("purchase", params); +}); + +var customMap = (function (map) { + config({ + custom_map: map + }); +}); + +var api = /*#__PURE__*/Object.freeze({ + __proto__: null, + query: query, + config: config, + optOut: optOut, + optIn: optIn, + pageview: pageview, + screenview: screenview, + exception: exception, + linker: linker, + time: time, + set: set, + refund: refund, + purchase: purchase, + customMap: customMap, + event: event +}); + +var attachApi = function attachApi(Vue) { + return Vue.$gtag = Vue.prototype.$gtag = api; +}; + +var registerGlobals = (function () { + if (!isBrowser()) { + return; + } + + var _getOptions = getOptions(), + enabled = _getOptions.enabled, + globalObjectName = _getOptions.globalObjectName, + globalDataLayerName = _getOptions.globalDataLayerName; + + if (window[globalObjectName] == null) { + window[globalDataLayerName] = window[globalDataLayerName] || []; + + window[globalObjectName] = function () { + window[globalDataLayerName].push(arguments); + }; + } + + window[globalObjectName]("js", new Date()); + + if (!enabled) { + optOut(); + } + + return window[globalObjectName]; +}); + +var mergeDefaultParams = function mergeDefaultParams(params) { + return _objectSpread2({ + send_page_view: false + }, params); +}; + +var addConfiguration = (function () { + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + query("config", config.id, mergeDefaultParams(config.params)); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + query("config", domain.id, mergeDefaultParams(domain.params)); + }); + } + + if (config.customClientId) { + query("set", { + client_id: config.custom_client_id + }); + } +}); + +var track = (function () { + var to = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var _getOptions = getOptions(), + appName = _getOptions.appName, + proxy = _getOptions.pageTrackerTemplate, + useScreenview = _getOptions.pageTrackerScreenviewEnabled, + skipSamePath = _getOptions.pageTrackerSkipSamePath; + + if (skipSamePath && to.path === from.path) { + return; + } + + var template = to; + + if (isFn(proxy)) { + template = proxy(to, from); + } else if (useScreenview) { + template = validateScreenviewShape({ + app_name: appName, + screen_name: to.name + }); + } + + if (useScreenview) { + screenview(template); + return; + } + + pageview(template); +}); + +var isRouteExcluded = function isRouteExcluded(route) { + var _getOptions = getOptions(), + routes = _getOptions.pageTrackerExcludedRoutes; + + return routes.includes(route.path) || routes.includes(route.name); +}; + +var addRoutesTracker = (function () { + var _getOptions2 = getOptions(), + onBeforeTrack = _getOptions2.onBeforeTrack, + onAfterTrack = _getOptions2.onAfterTrack; + + var router = getRouter(); + router.onReady(function () { + Vue.nextTick().then(function () { + var currentRoute = router.currentRoute; + addConfiguration(); + + if (isRouteExcluded(currentRoute)) { + return; + } + + track(currentRoute); + }); + router.afterEach(function (to, from) { + Vue.nextTick().then(function () { + if (isRouteExcluded(to)) { + return; + } + + if (isFn(onBeforeTrack)) { + onBeforeTrack(to, from); + } + + track(to, from); + + if (isFn(onAfterTrack)) { + onAfterTrack(to, from); + } + }); + }); + }); +}); + +var bootstrap = (function () { + var _getOptions = getOptions(), + onReady = _getOptions.onReady, + onError = _getOptions.onError, + globalObjectName = _getOptions.globalObjectName, + globalDataLayerName = _getOptions.globalDataLayerName, + config = _getOptions.config, + customResourceURL = _getOptions.customResourceURL, + customPreconnectOrigin = _getOptions.customPreconnectOrigin, + deferScriptLoad = _getOptions.deferScriptLoad, + pageTrackerEnabled = _getOptions.pageTrackerEnabled, + disableScriptLoad = _getOptions.disableScriptLoad; + + var isPageTrackerEnabled = Boolean(pageTrackerEnabled && getRouter()); + registerGlobals(); + + if (isPageTrackerEnabled) { + addRoutesTracker(); + } else { + addConfiguration(); + } + + if (disableScriptLoad) { + return; + } + + return load("".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName), { + preconnectOrigin: customPreconnectOrigin, + defer: deferScriptLoad + }).then(function () { + if (onReady) { + onReady(window[globalObjectName]); + } + }).catch(function (error) { + if (onError) { + onError(error); + } + + return error; + }); +}); + +var install = function install(Vue) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var router = arguments.length > 2 ? arguments[2] : undefined; + attachApi(Vue); + setOptions(options); + setRouter(router); + + if (getOptions().bootstrap) { + bootstrap(); + } +}; + +exports.addRoutesTracker = addRoutesTracker; +exports.bootstrap = bootstrap; +exports.config = config; +exports.customMap = customMap; +exports.default = install; +exports.event = event; +exports.exception = exception; +exports.install = install; +exports.linker = linker; +exports.optIn = optIn; +exports.optOut = optOut; +exports.pageview = pageview; +exports.purchase = purchase; +exports.query = query; +exports.refund = refund; +exports.screenview = screenview; +exports.set = set; +exports.setOptions = setOptions; +exports.setRouter = setRouter; +exports.time = time; diff --git a/dist/vue-gtag.umd.js b/dist/vue-gtag.umd.js new file mode 100644 index 0000000..2df59dc --- /dev/null +++ b/dist/vue-gtag.umd.js @@ -0,0 +1,635 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) : + typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) : + (global = global || self, factory(global.VueGtag = {}, global.Vue)); +}(this, (function (exports, Vue) { 'use strict'; + + Vue = Vue && Object.prototype.hasOwnProperty.call(Vue, 'default') ? Vue['default'] : Vue; + + function _typeof(obj) { + "@babel/helpers - typeof"; + + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + + if (i % 2) { + ownKeys(Object(source), true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + } + + return target; + } + + var load = function load(url) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + return new Promise(function (resolve, reject) { + if (typeof document === "undefined") { + return; + } + + var head = document.head || document.getElementsByTagName("head")[0]; + var script = document.createElement("script"); + script.async = true; + script.src = url; + script.defer = options.defer; + + if (options.preconnectOrigin) { + var link = document.createElement("link"); + link.href = options.preconnectOrigin; + link.rel = "preconnect"; + head.appendChild(link); + } + + head.appendChild(script); + script.onload = resolve; + script.onerror = reject; + }); + }; + var isFn = function isFn(fn) { + return typeof fn === "function"; + }; + var isObject = function isObject(item) { + return item && _typeof(item) === "object" && !Array.isArray(item); + }; + var mergeDeep = function mergeDeep(target) { + for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + sources[_key - 1] = arguments[_key]; + } + + if (!sources.length) { + return target; + } + + var source = sources.shift(); + + if (!isObject(target) || !isObject(source)) { + return; + } + + for (var key in source) { + if (isObject(source[key])) { + if (!target[key]) { + Object.assign(target, _defineProperty({}, key, {})); + } + + mergeDeep(target[key], source[key]); + } else { + Object.assign(target, _defineProperty({}, key, source[key])); + } + } + + return mergeDeep.apply(void 0, [target].concat(sources)); + }; + var isBrowser = function isBrowser() { + if (typeof window === "undefined" || typeof document === "undefined") { + return false; + } + + return true; + }; + var warn = function warn(text) { + var shouldLog = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + + if (!isBrowser() || "development" === "production") { + return; + } + + if (!shouldLog) { + return; + } + + console.warn("[vue-gtag] ".concat(text)); + }; + var validateScreenviewShape = function validateScreenviewShape() { + var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + warn("Missing \"appName\" property inside the plugin options.", obj.app_name == null); + warn("Missing \"name\" property in the route.", obj.screen_name == null); + return obj; + }; + function getPathWithBase() { + var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; + var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; + var pathAsArray = path.split("/"); + var baseAsArray = base.split("/"); + + if (pathAsArray[0] === "" && base[base.length - 1] === "/") { + pathAsArray.shift(); + } + + return baseAsArray.join("/") + pathAsArray.join("/"); + } + + var getDefaultParams = function getDefaultParams() { + return { + bootstrap: true, + onReady: null, + onError: null, + onBeforeTrack: null, + onAfterTrack: null, + pageTrackerTemplate: null, + customResourceURL: "https://www.googletagmanager.com/gtag/js", + customPreconnectOrigin: "https://www.googletagmanager.com", + deferScriptLoad: false, + pageTrackerExcludedRoutes: [], + pageTrackerEnabled: true, + enabled: true, + disableScriptLoad: false, + pageTrackerScreenviewEnabled: false, + appName: null, + pageTrackerUseFullPath: false, + pageTrackerPrependBase: true, + pageTrackerSkipSamePath: true, + globalDataLayerName: "dataLayer", + globalObjectName: "gtag", + defaultGroupName: "default", + includes: null, + config: { + id: null, + params: { + send_page_view: false + } + }, + customClientId: "" + }; + }; + var params = {}; + var setOptions = function setOptions() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var defaultParams = getDefaultParams(); + params = mergeDeep(defaultParams, options); + }; + var getOptions = function getOptions() { + return params; + }; + + var query = (function () { + var _window; + + if (!isBrowser()) { + return; + } + + var _getOptions = getOptions(), + globalObjectName = _getOptions.globalObjectName; + + (_window = window)[globalObjectName].apply(_window, arguments); + }); + + var config = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + query.apply(void 0, ["config", config.id].concat(args)); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + query.apply(void 0, ["config", domain.id].concat(args)); + }); + } + }); + + var assignGlobalProperty = function assignGlobalProperty(id, value) { + if (!isBrowser()) { + return; + } + + window["ga-disable-".concat(id)] = value; + }; + + var disable = (function () { + var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + assignGlobalProperty(config.id, value); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + return assignGlobalProperty(domain.id, value); + }); + } + }); + + var optOut = (function () { + disable(true); + }); + + var optIn = (function () { + disable(false); + }); + + var router; + var setRouter = function setRouter(instance) { + router = instance; + }; + var getRouter = function getRouter() { + return router; + }; + + var event = (function (name) { + var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var _getOptions = getOptions(), + includes = _getOptions.includes, + defaultGroupName = _getOptions.defaultGroupName; + + if (params.send_to == null && Array.isArray(includes) && includes.length) { + params.send_to = includes.map(function (domain) { + return domain.id; + }).concat(defaultGroupName); + } + + query("event", name, params); + }); + + var pageview = (function (param) { + if (!isBrowser()) { + return; + } + + var template; + + if (typeof param === "string") { + template = { + page_path: param + }; + } else if (param.path || param.fullPath) { + var _getOptions = getOptions(), + useFullPath = _getOptions.pageTrackerUseFullPath, + useBase = _getOptions.pageTrackerPrependBase; + + var router = getRouter(); + var base = router && router.options.base; + var path = useFullPath ? param.fullPath : param.path; + template = _objectSpread2(_objectSpread2({}, param.name && { + page_title: param.name + }), {}, { + page_path: useBase ? getPathWithBase(path, base) : path + }); + } else { + template = param; + } + + if (template.page_location == null) { + template.page_location = window.location.href; + } + + if (template.send_page_view == null) { + template.send_page_view = true; + } + + event("page_view", template); + }); + + var screenview = (function (param) { + var _getOptions = getOptions(), + appName = _getOptions.appName; + + if (!param) { + return; + } + + var template; + + if (typeof param === "string") { + template = { + screen_name: param + }; + } else { + template = param; + } + + template.app_name = template.app_name || appName; + event("screen_view", template); + }); + + var exception = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + event.apply(void 0, ["exception"].concat(args)); + }); + + var linker = (function (params) { + config("linker", params); + }); + + var time = (function (params) { + event("timing_complete", params); + }); + + var set = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + query.apply(void 0, ["set"].concat(args)); + }); + + var refund = (function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + event.apply(void 0, ["refund"].concat(args)); + }); + + var purchase = (function (params) { + event("purchase", params); + }); + + var customMap = (function (map) { + config({ + custom_map: map + }); + }); + + var api = /*#__PURE__*/Object.freeze({ + __proto__: null, + query: query, + config: config, + optOut: optOut, + optIn: optIn, + pageview: pageview, + screenview: screenview, + exception: exception, + linker: linker, + time: time, + set: set, + refund: refund, + purchase: purchase, + customMap: customMap, + event: event + }); + + var attachApi = function attachApi(Vue) { + return Vue.$gtag = Vue.prototype.$gtag = api; + }; + + var registerGlobals = (function () { + if (!isBrowser()) { + return; + } + + var _getOptions = getOptions(), + enabled = _getOptions.enabled, + globalObjectName = _getOptions.globalObjectName, + globalDataLayerName = _getOptions.globalDataLayerName; + + if (window[globalObjectName] == null) { + window[globalDataLayerName] = window[globalDataLayerName] || []; + + window[globalObjectName] = function () { + window[globalDataLayerName].push(arguments); + }; + } + + window[globalObjectName]("js", new Date()); + + if (!enabled) { + optOut(); + } + + return window[globalObjectName]; + }); + + var mergeDefaultParams = function mergeDefaultParams(params) { + return _objectSpread2({ + send_page_view: false + }, params); + }; + + var addConfiguration = (function () { + var _getOptions = getOptions(), + config = _getOptions.config, + includes = _getOptions.includes; + + query("config", config.id, mergeDefaultParams(config.params)); + + if (Array.isArray(includes)) { + includes.forEach(function (domain) { + query("config", domain.id, mergeDefaultParams(domain.params)); + }); + } + + if (config.customClientId) { + query("set", { + client_id: config.custom_client_id + }); + } + }); + + var track = (function () { + var to = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var _getOptions = getOptions(), + appName = _getOptions.appName, + proxy = _getOptions.pageTrackerTemplate, + useScreenview = _getOptions.pageTrackerScreenviewEnabled, + skipSamePath = _getOptions.pageTrackerSkipSamePath; + + if (skipSamePath && to.path === from.path) { + return; + } + + var template = to; + + if (isFn(proxy)) { + template = proxy(to, from); + } else if (useScreenview) { + template = validateScreenviewShape({ + app_name: appName, + screen_name: to.name + }); + } + + if (useScreenview) { + screenview(template); + return; + } + + pageview(template); + }); + + var isRouteExcluded = function isRouteExcluded(route) { + var _getOptions = getOptions(), + routes = _getOptions.pageTrackerExcludedRoutes; + + return routes.includes(route.path) || routes.includes(route.name); + }; + + var addRoutesTracker = (function () { + var _getOptions2 = getOptions(), + onBeforeTrack = _getOptions2.onBeforeTrack, + onAfterTrack = _getOptions2.onAfterTrack; + + var router = getRouter(); + router.onReady(function () { + Vue.nextTick().then(function () { + var currentRoute = router.currentRoute; + addConfiguration(); + + if (isRouteExcluded(currentRoute)) { + return; + } + + track(currentRoute); + }); + router.afterEach(function (to, from) { + Vue.nextTick().then(function () { + if (isRouteExcluded(to)) { + return; + } + + if (isFn(onBeforeTrack)) { + onBeforeTrack(to, from); + } + + track(to, from); + + if (isFn(onAfterTrack)) { + onAfterTrack(to, from); + } + }); + }); + }); + }); + + var bootstrap = (function () { + var _getOptions = getOptions(), + onReady = _getOptions.onReady, + onError = _getOptions.onError, + globalObjectName = _getOptions.globalObjectName, + globalDataLayerName = _getOptions.globalDataLayerName, + config = _getOptions.config, + customResourceURL = _getOptions.customResourceURL, + customPreconnectOrigin = _getOptions.customPreconnectOrigin, + deferScriptLoad = _getOptions.deferScriptLoad, + pageTrackerEnabled = _getOptions.pageTrackerEnabled, + disableScriptLoad = _getOptions.disableScriptLoad; + + var isPageTrackerEnabled = Boolean(pageTrackerEnabled && getRouter()); + registerGlobals(); + + if (isPageTrackerEnabled) { + addRoutesTracker(); + } else { + addConfiguration(); + } + + if (disableScriptLoad) { + return; + } + + return load("".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName), { + preconnectOrigin: customPreconnectOrigin, + defer: deferScriptLoad + }).then(function () { + if (onReady) { + onReady(window[globalObjectName]); + } + }).catch(function (error) { + if (onError) { + onError(error); + } + + return error; + }); + }); + + var install = function install(Vue) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + var router = arguments.length > 2 ? arguments[2] : undefined; + attachApi(Vue); + setOptions(options); + setRouter(router); + + if (getOptions().bootstrap) { + bootstrap(); + } + }; + + exports.addRoutesTracker = addRoutesTracker; + exports.bootstrap = bootstrap; + exports.config = config; + exports.customMap = customMap; + exports.default = install; + exports.event = event; + exports.exception = exception; + exports.install = install; + exports.linker = linker; + exports.optIn = optIn; + exports.optOut = optOut; + exports.pageview = pageview; + exports.purchase = purchase; + exports.query = query; + exports.refund = refund; + exports.screenview = screenview; + exports.set = set; + exports.setOptions = setOptions; + exports.setRouter = setRouter; + exports.time = time; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/dist/vue-gtag.umd.min.js b/dist/vue-gtag.umd.min.js new file mode 100644 index 0000000..55cbc90 --- /dev/null +++ b/dist/vue-gtag.umd.min.js @@ -0,0 +1,2 @@ +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],n):n((e=e||self).VueGtag={},e.Vue)}(this,(function(e,n){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function a(e){for(var n=1;n1?t-1:0),a=1;a0&&void 0!==arguments[0]?arguments[0]:{};return p('Missing "appName" property inside the plugin options.',null==e.app_name),p('Missing "name" property in the route.',null==e.screen_name),e};function d(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=e.split("/"),r=n.split("/");return""===t[0]&&"/"===n[n.length-1]&&t.shift(),r.join("/")+t.join("/")}var s,g={},m=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n={bootstrap:!0,onReady:null,onError:null,onBeforeTrack:null,onAfterTrack:null,pageTrackerTemplate:null,customResourceURL:"https://www.googletagmanager.com/gtag/js",customPreconnectOrigin:"https://www.googletagmanager.com",deferScriptLoad:!1,pageTrackerExcludedRoutes:[],pageTrackerEnabled:!0,enabled:!0,disableScriptLoad:!1,pageTrackerScreenviewEnabled:!1,appName:null,pageTrackerUseFullPath:!1,pageTrackerPrependBase:!0,pageTrackerSkipSamePath:!0,globalDataLayerName:"dataLayer",globalObjectName:"gtag",defaultGroupName:"default",includes:null,config:{id:null,params:{send_page_view:!1}},customClientId:""};g=u(n,e)},y=function(){return g},v=function(){var e;if(l()){var n=y(),t=n.globalObjectName;(e=window)[t].apply(e,arguments)}},h=function(){for(var e=arguments.length,n=new Array(e),t=0;t0&&void 0!==arguments[0])||arguments[0],n=y(),t=n.config,r=n.includes;w(t.id,e),Array.isArray(r)&&r.forEach((function(n){return w(n.id,e)}))},O=function(){b(!0)},_=function(){b(!1)},k=function(e){s=e},j=function(){return s},T=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=y(),r=t.includes,o=t.defaultGroupName;null==n.send_to&&Array.isArray(r)&&r.length&&(n.send_to=r.map((function(e){return e.id})).concat(o)),v("event",e,n)},P=function(e){if(l()){var n;if("string"==typeof e)n={page_path:e};else if(e.path||e.fullPath){var t=y(),r=t.pageTrackerUseFullPath,o=t.pageTrackerPrependBase,i=j(),c=i&&i.options.base,u=r?e.fullPath:e.path;n=a(a({},e.name&&{page_title:e.name}),{},{page_path:o?d(u,c):u})}else n=e;null==n.page_location&&(n.page_location=window.location.href),null==n.send_page_view&&(n.send_page_view=!0),T("page_view",n)}},A=function(e){var n,t=y().appName;e&&((n="string"==typeof e?{screen_name:e}:e).app_name=n.app_name||t,T("screen_view",n))},E=function(){for(var e=arguments.length,n=new Array(e),t=0;t0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=y(),r=t.appName,o=t.pageTrackerTemplate,a=t.pageTrackerScreenviewEnabled,c=t.pageTrackerSkipSamePath;if(!c||e.path!==n.path){var u=e;i(o)?u=o(e,n):a&&(u=f({app_name:r,screen_name:e.name})),a?A(u):P(u)}},q=function(e){var n=y().pageTrackerExcludedRoutes;return n.includes(e.path)||n.includes(e.name)},G=function(){var e=y(),t=e.onBeforeTrack,r=e.onAfterTrack,o=j();o.onReady((function(){n.nextTick().then((function(){var e=o.currentRoute;I(),q(e)||U(e)})),o.afterEach((function(e,o){n.nextTick().then((function(){q(e)||(i(t)&&t(e,o),U(e,o),i(r)&&r(e,o))}))}))}))},F=function(){var e=y(),n=e.onReady,t=e.onError,r=e.globalObjectName,o=e.globalDataLayerName,a=e.config,i=e.customResourceURL,c=e.customPreconnectOrigin,u=e.deferScriptLoad,p=e.pageTrackerEnabled,f=e.disableScriptLoad,d=Boolean(p&&j());if(function(){if(l()){var e=y(),n=e.enabled,t=e.globalObjectName,r=e.globalDataLayerName;null==window[t]&&(window[r]=window[r]||[],window[t]=function(){window[r].push(arguments)}),window[t]("js",new Date),n||O(),window[t]}}(),d?G():I(),!f)return function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(t,r){if("undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],a=document.createElement("script");if(a.async=!0,a.src=e,a.defer=n.defer,n.preconnectOrigin){var i=document.createElement("link");i.href=n.preconnectOrigin,i.rel="preconnect",o.appendChild(i)}o.appendChild(a),a.onload=t,a.onerror=r}}))}("".concat(i,"?id=").concat(a.id,"&l=").concat(o),{preconnectOrigin:c,defer:u}).then((function(){n&&n(window[r])})).catch((function(e){return t&&t(e),e}))},V=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2?arguments[2]:void 0;M(e),m(n),k(t),y().bootstrap&&F()};e.addRoutesTracker=G,e.bootstrap=F,e.config=h,e.customMap=D,e.default=V,e.event=T,e.exception=E,e.install=V,e.linker=S,e.optIn=_,e.optOut=O,e.pageview=P,e.purchase=L,e.query=v,e.refund=x,e.screenview=A,e.set=R,e.setOptions=m,e.setRouter=k,e.time=N,Object.defineProperty(e,"__esModule",{value:!0})})); +//# sourceMappingURL=vue-gtag.umd.min.js.map diff --git a/dist/vue-gtag.umd.min.js.map b/dist/vue-gtag.umd.min.js.map new file mode 100644 index 0000000..3fd3938 --- /dev/null +++ b/dist/vue-gtag.umd.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"vue-gtag.umd.min.js","sources":["../src/utils.js","../src/options.js","../src/router.js","../src/api/query.js","../src/api/config.js","../src/api/disable.js","../src/api/opt-out.js","../src/api/opt-in.js","../src/api/event.js","../src/api/pageview.js","../src/api/screenview.js","../src/api/exception.js","../src/api/linker.js","../src/api/time.js","../src/api/set.js","../src/api/refund.js","../src/api/purchase.js","../src/api/custom-map.js","../src/attach-api.js","../src/add-configuration.js","../src/track.js","../src/add-routes-tracker.js","../src/bootstrap.js","../src/register-globals.js","../src/index.js"],"sourcesContent":["export const load = (url, options = {}) => {\n return new Promise((resolve, reject) => {\n if (typeof document === \"undefined\") {\n return;\n }\n\n const head = document.head || document.getElementsByTagName(\"head\")[0];\n const script = document.createElement(\"script\");\n\n script.async = true;\n script.src = url;\n script.defer = options.defer;\n\n if (options.preconnectOrigin) {\n const link = document.createElement(\"link\");\n\n link.href = options.preconnectOrigin;\n link.rel = \"preconnect\";\n\n head.appendChild(link);\n }\n\n head.appendChild(script);\n\n script.onload = resolve;\n script.onerror = reject;\n });\n};\n\nexport const isFn = (fn) => typeof fn === \"function\";\n\nexport const isObject = (item) => {\n return item && typeof item === \"object\" && !Array.isArray(item);\n};\n\nexport const mergeDeep = (target, ...sources) => {\n if (!sources.length) {\n return target;\n }\n\n const source = sources.shift();\n\n if (!isObject(target) || !isObject(source)) {\n return;\n }\n\n for (const key in source) {\n if (isObject(source[key])) {\n if (!target[key]) {\n Object.assign(target, { [key]: {} });\n }\n\n mergeDeep(target[key], source[key]);\n } else {\n Object.assign(target, { [key]: source[key] });\n }\n }\n\n return mergeDeep(target, ...sources);\n};\n\nexport const isBrowser = () => {\n if (typeof window === \"undefined\" || typeof document === \"undefined\") {\n return false;\n }\n\n return true;\n};\n\nexport const warn = (text, shouldLog = true) => {\n if (!isBrowser() || process.env.NODE_ENV === \"production\") {\n return;\n }\n\n if (!shouldLog) {\n return;\n }\n\n console.warn(`[vue-gtag] ${text}`);\n};\n\nexport const validateScreenviewShape = (obj = {}) => {\n warn(\n `Missing \"appName\" property inside the plugin options.`,\n obj.app_name == null\n );\n\n warn(`Missing \"name\" property in the route.`, obj.screen_name == null);\n\n return obj;\n};\n\nexport function getPathWithBase(path = \"\", base = \"\") {\n const pathAsArray = path.split(\"/\");\n const baseAsArray = base.split(\"/\");\n\n if (pathAsArray[0] === \"\" && base[base.length - 1] === \"/\") {\n pathAsArray.shift();\n }\n\n return baseAsArray.join(\"/\") + pathAsArray.join(\"/\");\n}\n","import { mergeDeep } from \"@/utils\";\n\nexport const getDefaultParams = () => ({\n bootstrap: true,\n onReady: null,\n onError: null,\n onBeforeTrack: null,\n onAfterTrack: null,\n pageTrackerTemplate: null,\n customResourceURL: \"https://www.googletagmanager.com/gtag/js\",\n customPreconnectOrigin: \"https://www.googletagmanager.com\",\n deferScriptLoad: false,\n pageTrackerExcludedRoutes: [],\n pageTrackerEnabled: true,\n enabled: true,\n disableScriptLoad: false,\n pageTrackerScreenviewEnabled: false,\n appName: null,\n pageTrackerUseFullPath: false,\n pageTrackerPrependBase: true,\n pageTrackerSkipSamePath: true,\n globalDataLayerName: \"dataLayer\",\n globalObjectName: \"gtag\",\n defaultGroupName: \"default\",\n includes: null,\n config: {\n id: null,\n params: {\n send_page_view: false,\n },\n },\n customClientId: \"\"\n});\n\nlet params = {};\n\nexport const setOptions = (options = {}) => {\n const defaultParams = getDefaultParams();\n params = mergeDeep(defaultParams, options);\n};\n\nexport const getOptions = () => {\n return params;\n};\n","let router;\n\nexport const setRouter = (instance) => {\n router = instance;\n};\n\nexport const getRouter = () => router;\n\nexport default router;\n","import { getOptions } from \"@/options\";\nimport { isBrowser } from \"@/utils\";\n\nexport default (...args) => {\n if (!isBrowser()) {\n return;\n }\n\n const { globalObjectName } = getOptions();\n\n window[globalObjectName](...args);\n};\n","import query from \"@/api/query\";\nimport { getOptions } from \"@/options\";\n\nexport default (...args) => {\n const { config, includes } = getOptions();\n\n query(\"config\", config.id, ...args);\n\n if (Array.isArray(includes)) {\n includes.forEach((domain) => {\n query(\"config\", domain.id, ...args);\n });\n }\n};\n","import { isBrowser } from \"@/utils\";\nimport { getOptions } from \"@/options\";\n\nconst assignGlobalProperty = (id, value) => {\n if (!isBrowser()) {\n return;\n }\n\n window[`ga-disable-${id}`] = value;\n};\n\nexport default (value = true) => {\n const { config, includes } = getOptions();\n\n assignGlobalProperty(config.id, value);\n\n if (Array.isArray(includes)) {\n includes.forEach((domain) => assignGlobalProperty(domain.id, value));\n }\n};\n","import disable from \"@/api/disable\";\n\nexport default () => {\n disable(true);\n};\n","import disable from \"@/api/disable\";\n\nexport default () => {\n disable(false);\n};\n","import { getOptions } from \"@/options\";\nimport query from \"@/api/query\";\n\nexport default (name, params = {}) => {\n const { includes, defaultGroupName } = getOptions();\n\n if (params.send_to == null && Array.isArray(includes) && includes.length) {\n params.send_to = includes\n .map((domain) => domain.id)\n .concat(defaultGroupName);\n }\n\n query(\"event\", name, params);\n};\n","import { getOptions } from \"@/options\";\nimport { getRouter } from \"@/router\";\nimport { getPathWithBase, isBrowser } from \"@/utils\";\nimport event from \"@/api/event\";\n\nexport default (param) => {\n if (!isBrowser()) {\n return;\n }\n\n let template;\n\n if (typeof param === \"string\") {\n template = {\n page_path: param,\n };\n } else if (param.path || param.fullPath) {\n const {\n pageTrackerUseFullPath: useFullPath,\n pageTrackerPrependBase: useBase,\n } = getOptions();\n const router = getRouter();\n const base = router && router.options.base;\n const path = useFullPath ? param.fullPath : param.path;\n\n template = {\n ...(param.name && { page_title: param.name }),\n page_path: useBase ? getPathWithBase(path, base) : path,\n };\n } else {\n template = param;\n }\n\n if (template.page_location == null) {\n template.page_location = window.location.href;\n }\n\n if (template.send_page_view == null) {\n template.send_page_view = true;\n }\n\n event(\"page_view\", template);\n};\n","import { getOptions } from \"@/options\";\nimport event from \"@/api/event\";\n\nexport default (param) => {\n const { appName } = getOptions();\n\n if (!param) {\n return;\n }\n\n let template;\n\n if (typeof param === \"string\") {\n template = {\n screen_name: param,\n };\n } else {\n template = param;\n }\n\n template.app_name = template.app_name || appName;\n\n event(\"screen_view\", template);\n};\n","import event from \"@/api/event\";\n\nexport default (...args) => {\n event(\"exception\", ...args);\n};\n","import config from \"./config\";\n\nexport default (params) => {\n config(\"linker\", params);\n};\n","import event from \"@/api/event\";\n\nexport default (params) => {\n event(\"timing_complete\", params);\n};\n","import query from \"@/api/query\";\n\nexport default (...args) => {\n query(\"set\", ...args);\n};\n","import event from \"@/api/event\";\n\nexport default (...args) => {\n event(\"refund\", ...args);\n};\n","import event from \"@/api/event\";\n\nexport default (params) => {\n event(\"purchase\", params);\n};\n","import config from \"@/api/config\";\n\nexport default (map) => {\n config({\n custom_map: map,\n });\n};\n","import * as api from \"@/api\";\n\nconst attachApi = (Vue) => (Vue.$gtag = Vue.prototype.$gtag = api);\n\nexport default attachApi;\n","import * as api from \"@/api\";\nimport { getOptions } from \"@/options\";\n\nconst mergeDefaultParams = (params) => ({\n send_page_view: false,\n ...params,\n});\n\nexport default () => {\n const { config, includes } = getOptions();\n\n api.query(\"config\", config.id, mergeDefaultParams(config.params));\n\n if (Array.isArray(includes)) {\n includes.forEach((domain) => {\n api.query(\"config\", domain.id, mergeDefaultParams(domain.params));\n });\n }\n\n if (config.customClientId) {\n api.query(\"set\", { client_id: config.custom_client_id });\n }\n};\n","import { getOptions } from \"@/options\";\nimport { validateScreenviewShape, isFn } from \"@/utils\";\nimport * as api from \"@/api\";\n\nexport default (to = {}, from = {}) => {\n const {\n appName,\n pageTrackerTemplate: proxy,\n pageTrackerScreenviewEnabled: useScreenview,\n pageTrackerSkipSamePath: skipSamePath,\n } = getOptions();\n\n if (skipSamePath && to.path === from.path) {\n return;\n }\n\n let template = to;\n\n if (isFn(proxy)) {\n template = proxy(to, from);\n } else if (useScreenview) {\n template = validateScreenviewShape({\n app_name: appName,\n screen_name: to.name,\n });\n }\n\n if (useScreenview) {\n api.screenview(template);\n return;\n }\n\n api.pageview(template);\n};\n","import Vue from \"vue\";\nimport { isFn } from \"@/utils\";\nimport { getRouter } from \"@/router\";\nimport { getOptions } from \"@/options\";\nimport addConfiguration from \"@/add-configuration\";\nimport track from \"@/track\";\n\nconst isRouteExcluded = (route) => {\n const { pageTrackerExcludedRoutes: routes } = getOptions();\n return routes.includes(route.path) || routes.includes(route.name);\n};\n\nexport default () => {\n const { onBeforeTrack, onAfterTrack } = getOptions();\n const router = getRouter();\n\n router.onReady(() => {\n Vue.nextTick().then(() => {\n const { currentRoute } = router;\n\n addConfiguration();\n\n if (isRouteExcluded(currentRoute)) {\n return;\n }\n\n track(currentRoute);\n });\n\n router.afterEach((to, from) => {\n Vue.nextTick().then(() => {\n if (isRouteExcluded(to)) {\n return;\n }\n\n if (isFn(onBeforeTrack)) {\n onBeforeTrack(to, from);\n }\n\n track(to, from);\n\n if (isFn(onAfterTrack)) {\n onAfterTrack(to, from);\n }\n });\n });\n });\n};\n","import { load } from \"@/utils\";\nimport registerGlobals from \"@/register-globals\";\nimport addRoutesTracker from \"@/add-routes-tracker\";\nimport { getOptions } from \"@/options\";\nimport { getRouter } from \"@/router\";\nimport addConfiguration from \"@/add-configuration\";\n\nexport default () => {\n const {\n onReady,\n onError,\n globalObjectName,\n globalDataLayerName,\n config,\n customResourceURL,\n customPreconnectOrigin,\n deferScriptLoad,\n pageTrackerEnabled,\n disableScriptLoad,\n } = getOptions();\n\n const isPageTrackerEnabled = Boolean(pageTrackerEnabled && getRouter());\n\n registerGlobals();\n\n if (isPageTrackerEnabled) {\n addRoutesTracker();\n } else {\n addConfiguration();\n }\n\n if (disableScriptLoad) {\n return;\n }\n\n return load(`${customResourceURL}?id=${config.id}&l=${globalDataLayerName}`, {\n preconnectOrigin: customPreconnectOrigin,\n defer: deferScriptLoad,\n })\n .then(() => {\n if (onReady) {\n onReady(window[globalObjectName]);\n }\n })\n .catch((error) => {\n if (onError) {\n onError(error);\n }\n\n return error;\n });\n};\n","import { isBrowser } from \"@/utils\";\nimport { getOptions } from \"@/options\";\nimport * as api from \"@/api\";\n\nexport default () => {\n if (!isBrowser()) {\n return;\n }\n\n const { enabled, globalObjectName, globalDataLayerName } = getOptions();\n\n if (window[globalObjectName] == null) {\n window[globalDataLayerName] = window[globalDataLayerName] || [];\n window[globalObjectName] = function () {\n window[globalDataLayerName].push(arguments);\n };\n }\n\n window[globalObjectName](\"js\", new Date());\n\n if (!enabled) {\n api.optOut();\n }\n\n return window[globalObjectName];\n};\n","import attachApi from \"@/attach-api\";\nimport { setOptions, getOptions } from \"@/options\";\nimport bootstrap from \"@/bootstrap\";\nimport { setRouter } from \"@/router\";\n\nconst install = (Vue, options = {}, router) => {\n attachApi(Vue);\n setOptions(options);\n setRouter(router);\n\n if (getOptions().bootstrap) {\n bootstrap();\n }\n};\n\nexport { default as query } from \"@/api/query\";\nexport { default as config } from \"@/api/config\";\nexport { default as optOut } from \"@/api/opt-out\";\nexport { default as optIn } from \"@/api/opt-in\";\nexport { default as pageview } from \"@/api/pageview\";\nexport { default as screenview } from \"@/api/screenview\";\nexport { default as exception } from \"@/api/exception\";\nexport { default as linker } from \"@/api/linker\";\nexport { default as time } from \"@/api/time\";\nexport { default as set } from \"@/api/set\";\nexport { default as refund } from \"@/api/refund\";\nexport { default as purchase } from \"@/api/purchase\";\nexport { default as customMap } from \"@/api/custom-map\";\nexport { default as event } from \"@/api/event\";\n\nexport { default as bootstrap } from \"@/bootstrap\";\nexport { default as addRoutesTracker } from \"@/add-routes-tracker\";\n\nexport { setOptions } from \"@/options\";\nexport { setRouter } from \"@/router\";\n\nexport { install };\n\nexport default install;\n"],"names":["isFn","fn","isObject","item","_typeof","Array","isArray","mergeDeep","target","sources","length","source","shift","key","Object","assign","isBrowser","window","document","warn","text","validateScreenviewShape","obj","app_name","screen_name","getPathWithBase","path","base","pathAsArray","split","baseAsArray","join","router","params","setOptions","options","defaultParams","bootstrap","onReady","onError","onBeforeTrack","onAfterTrack","pageTrackerTemplate","customResourceURL","customPreconnectOrigin","deferScriptLoad","pageTrackerExcludedRoutes","pageTrackerEnabled","enabled","disableScriptLoad","pageTrackerScreenviewEnabled","appName","pageTrackerUseFullPath","pageTrackerPrependBase","pageTrackerSkipSamePath","globalDataLayerName","globalObjectName","defaultGroupName","includes","config","id","send_page_view","customClientId","getOptions","args","query","forEach","domain","assignGlobalProperty","value","disable","setRouter","instance","getRouter","name","send_to","map","concat","param","template","page_path","fullPath","useFullPath","useBase","page_title","page_location","location","href","event","custom_map","attachApi","Vue","$gtag","prototype","api","mergeDefaultParams","client_id","custom_client_id","to","from","proxy","useScreenview","skipSamePath","isRouteExcluded","route","routes","nextTick","then","currentRoute","addConfiguration","track","afterEach","isPageTrackerEnabled","Boolean","push","arguments","Date","registerGlobals","addRoutesTracker","url","Promise","resolve","reject","head","getElementsByTagName","script","createElement","async","src","defer","preconnectOrigin","link","rel","appendChild","onload","onerror","load","catch","error","install"],"mappings":"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"} \ No newline at end of file diff --git a/src/add-configuration.js b/src/add-configuration.js index b66e227..dde7219 100644 --- a/src/add-configuration.js +++ b/src/add-configuration.js @@ -16,4 +16,8 @@ export default () => { api.query("config", domain.id, mergeDefaultParams(domain.params)); }); } + + if (config.customClientId) { + api.query("set", { client_id: config.custom_client_id }); + } }; diff --git a/src/options.js b/src/options.js index c0a2a91..ec9d641 100644 --- a/src/options.js +++ b/src/options.js @@ -29,6 +29,7 @@ export const getDefaultParams = () => ({ send_page_view: false, }, }, + customClientId: "" }); let params = {};