Comparing version 1.14.0 to 1.14.1
@@ -0,1 +1,3 @@ | ||
import Vue from 'vue'; | ||
function _typeof(obj) { | ||
@@ -66,6 +68,9 @@ "@babel/helpers - typeof"; | ||
var noop = function noop() {}; | ||
function loadScript(url) { | ||
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]; | ||
@@ -75,3 +80,2 @@ var script = document.createElement("script"); | ||
script.src = url; | ||
script.charset = "utf-8"; | ||
script.defer = options.defer; | ||
@@ -90,13 +94,10 @@ | ||
}); | ||
} | ||
function warn(msg) { | ||
console.warn("[vue-gtag] " + msg); | ||
} | ||
function isFn(item) { | ||
return typeof item === "function"; | ||
} | ||
function isObject(item) { | ||
}; | ||
var isFn = function isFn(fn) { | ||
return typeof fn === "function"; | ||
}; | ||
var isObject = function isObject(item) { | ||
return item && _typeof(item) === "object" && !Array.isArray(item); | ||
} | ||
function mergeDeep(target) { | ||
}; | ||
var mergeDeep = function mergeDeep(target) { | ||
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -129,16 +130,76 @@ sources[_key - 1] = arguments[_key]; | ||
return mergeDeep.apply(void 0, [target].concat(sources)); | ||
} | ||
}; | ||
var isBrowser = function isBrowser() { | ||
if (typeof window === "undefined" || typeof document === "undefined") { | ||
return false; | ||
} | ||
function query () { | ||
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 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, | ||
pageTrackerEnabled: true, | ||
enabled: true, | ||
disableScriptLoad: false, | ||
pageTrackerScreenviewEnabled: false, | ||
appName: null, | ||
pageTrackerUseFullPath: false, | ||
pageTrackerSkipSamePath: true, | ||
globalDataLayerName: "dataLayer", | ||
globalObjectName: "gtag", | ||
defaultGroupName: "default", | ||
includes: null, | ||
config: { | ||
id: null, | ||
params: { | ||
send_page_view: false | ||
} | ||
} | ||
}; | ||
}; | ||
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; | ||
if (typeof document === "undefined" || typeof window === "undefined") { | ||
return; | ||
} | ||
(_window = window)[globalObjectName].apply(_window, arguments); | ||
} | ||
}); | ||
@@ -163,14 +224,40 @@ var config = (function () { | ||
var event = (function (name) { | ||
var _params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var assignGlobalProperty = function assignGlobalProperty(id, value) { | ||
window["ga-disable-".concat(id)] = value; | ||
}; | ||
var disable = (function () { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
var _getOptions = getOptions(), | ||
defaultGroupName = _getOptions.defaultGroupName, | ||
config = _getOptions.config, | ||
includes = _getOptions.includes; | ||
var params = _params; | ||
assignGlobalProperty(config.id, value); | ||
if (includes && params.send_to == null) { | ||
params.send_to = includes.map(function (include) { | ||
return include.id; | ||
if (Array.isArray(includes)) { | ||
includes.forEach(function (domain) { | ||
return assignGlobalProperty(domain.id, value); | ||
}); | ||
} | ||
}); | ||
var optOut = (function () { | ||
disable(true); | ||
}); | ||
var optIn = (function () { | ||
disable(false); | ||
}); | ||
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); | ||
@@ -182,70 +269,55 @@ } | ||
var pageview = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var pageview = (function (param) { | ||
var template; | ||
var arg = args[0]; | ||
var params = {}; | ||
if (typeof param === "string") { | ||
template = { | ||
page_path: param | ||
}; | ||
} else if (param.path || param.fullPath) { | ||
var _getOptions = getOptions(), | ||
pageTrackerUseFullPath = _getOptions.pageTrackerUseFullPath; | ||
if (typeof arg === "string") { | ||
params = { | ||
page_path: arg, | ||
page_location: window.location.href | ||
}; | ||
template = _objectSpread2(_objectSpread2({}, param.name && { | ||
page_title: param.name | ||
}), {}, { | ||
page_path: pageTrackerUseFullPath ? param.fullPath : param.path | ||
}); | ||
} else { | ||
params = arg; | ||
template = param; | ||
} | ||
if (params.send_page_view == null) { | ||
params.send_page_view = true; | ||
if (template.page_location == null) { | ||
template.page_location = window.location.href; | ||
} | ||
event("page_view", params); | ||
if (template.send_page_view == null) { | ||
template.send_page_view = true; | ||
} | ||
event("page_view", template); | ||
}); | ||
var screenview = (function () { | ||
var screenview = (function (param) { | ||
var _getOptions = getOptions(), | ||
appName = _getOptions.appName; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
if (!param) { | ||
return; | ||
} | ||
var arg = args[0]; | ||
var params = {}; | ||
var template; | ||
if (typeof arg === "string") { | ||
params = { | ||
screen_name: arg | ||
if (typeof param === "string") { | ||
template = { | ||
screen_name: param | ||
}; | ||
} else { | ||
params = arg; | ||
template = param; | ||
} | ||
if (params.app_name == null) { | ||
params.app_name = appName; | ||
} | ||
if (params.send_page_view == null) { | ||
params.send_page_view = true; | ||
} | ||
event("screen_view", params); | ||
template.app_name = template.app_name || appName; | ||
event("screen_view", template); | ||
}); | ||
var customMap = (function (map) { | ||
config({ | ||
custom_map: map | ||
}); | ||
}); | ||
var time = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
event.apply(void 0, ["timing_complete"].concat(args)); | ||
}); | ||
var exception = (function () { | ||
@@ -263,3 +335,7 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
var purchase = (function () { | ||
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++) { | ||
@@ -269,3 +345,3 @@ args[_key] = arguments[_key]; | ||
event.apply(void 0, ["purchase"].concat(args)); | ||
query.apply(void 0, ["set"].concat(args)); | ||
}); | ||
@@ -281,57 +357,90 @@ | ||
var set = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var purchase = (function (params) { | ||
event("purchase", params); | ||
}); | ||
query.apply(void 0, ["set"].concat(args)); | ||
var customMap = (function (map) { | ||
config({ | ||
custom_map: map | ||
}); | ||
}); | ||
var disable = (function () { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
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(), | ||
includes = _getOptions.includes, | ||
config = _getOptions.config; | ||
enabled = _getOptions.enabled, | ||
globalObjectName = _getOptions.globalObjectName, | ||
globalDataLayerName = _getOptions.globalDataLayerName; | ||
window["ga-disable-".concat(config.id)] = value; | ||
if (window[globalObjectName] == null) { | ||
window[globalDataLayerName] = window[globalDataLayerName] || []; | ||
if (Array.isArray(includes)) { | ||
includes.forEach(function (domain) { | ||
window["ga-disable-".concat(domain.id)] = value; | ||
}); | ||
window[globalObjectName] = function () { | ||
window[globalDataLayerName].push(arguments); | ||
}; | ||
} | ||
}); | ||
var optIn = (function () { | ||
disable(false); | ||
}); | ||
window[globalObjectName]("js", new Date()); | ||
var optOut = (function () { | ||
disable(true); | ||
if (!enabled) { | ||
optOut(); | ||
} | ||
return window[globalObjectName]; | ||
}); | ||
var api = { | ||
query: query, | ||
config: config, | ||
event: event, | ||
pageview: pageview, | ||
screenview: screenview, | ||
customMap: customMap, | ||
time: time, | ||
exception: exception, | ||
linker: linker, | ||
purchase: purchase, | ||
refund: refund, | ||
set: set, | ||
optIn: optIn, | ||
optOut: optOut | ||
var router; | ||
var setRouter = function setRouter(instance) { | ||
router = instance; | ||
}; | ||
var getRouter = function getRouter() { | ||
return router; | ||
}; | ||
var extend = (function () { | ||
var Vue = getVue(); | ||
Vue.$gtag = Vue.prototype.$gtag = api; | ||
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)); | ||
}); | ||
} | ||
}); | ||
var getPageviewTemplate = function getPageviewTemplate() { | ||
var track = (function () { | ||
var to = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -341,13 +450,14 @@ var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _getOptions = getOptions(), | ||
appName = _getOptions.appName, | ||
pageTrackerTemplate = _getOptions.pageTrackerTemplate, | ||
pageTrackerScreenviewEnabled = _getOptions.pageTrackerScreenviewEnabled, | ||
pageTrackerUseFullPath = _getOptions.pageTrackerUseFullPath, | ||
appName = _getOptions.appName; | ||
pageTrackerSkipSamePath = _getOptions.pageTrackerSkipSamePath; | ||
var template; | ||
var customTemplate = pageTrackerTemplate(to, from); | ||
var template = to; | ||
if (customTemplate) { | ||
template = customTemplate; | ||
if (isFn(pageTrackerTemplate)) { | ||
template = pageTrackerTemplate(to, from); | ||
} else if (pageTrackerScreenviewEnabled) { | ||
warn("Missing \"appName\" property inside the plugin options.", appName == null); | ||
warn("Missing \"name\" property in the route with path value \"".concat(to.path, "\"."), to.name == null); | ||
template = { | ||
@@ -357,25 +467,4 @@ app_name: appName, | ||
}; | ||
} else { | ||
template = { | ||
page_title: to.name, | ||
page_path: pageTrackerUseFullPath ? to.fullPath : to.path, | ||
page_location: window.location.href | ||
}; | ||
} | ||
return template; | ||
}; | ||
var trackPage = function trackPage() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$to = _ref.to, | ||
to = _ref$to === void 0 ? {} : _ref$to, | ||
_ref$from = _ref.from, | ||
from = _ref$from === void 0 ? {} : _ref$from, | ||
_ref$params = _ref.params, | ||
params = _ref$params === void 0 ? {} : _ref$params; | ||
var _getOptions2 = getOptions(), | ||
pageTrackerSkipSamePath = _getOptions2.pageTrackerSkipSamePath, | ||
pageTrackerScreenviewEnabled = _getOptions2.pageTrackerScreenviewEnabled; | ||
if (pageTrackerSkipSamePath && to.path === from.path) { | ||
@@ -385,99 +474,57 @@ return; | ||
var newParams = _objectSpread2(_objectSpread2({}, getPageviewTemplate(to, from)), params); | ||
if (pageTrackerScreenviewEnabled && !newParams.app_name) { | ||
warn("To use the screenview, add the appName to the plugin options"); | ||
return; | ||
} | ||
if (pageTrackerScreenviewEnabled && !newParams.screen_name) { | ||
warn("To use the screenview, name your routes"); | ||
return; | ||
} | ||
if (pageTrackerScreenviewEnabled) { | ||
screenview(newParams); | ||
screenview(template); | ||
return; | ||
} | ||
pageview(newParams); | ||
}; | ||
var startRouter = function startRouter(Router) { | ||
var Vue = getVue(); | ||
pageview(template); | ||
}); | ||
var _getOptions3 = getOptions(), | ||
onBeforeTrack = _getOptions3.onBeforeTrack, | ||
onAfterTrack = _getOptions3.onAfterTrack, | ||
config = _getOptions3.config; | ||
/* istanbul ignore next */ | ||
var addRoutesTracker = (function () { | ||
var _getOptions = getOptions(), | ||
onBeforeTrack = _getOptions.onBeforeTrack, | ||
onAfterTrack = _getOptions.onAfterTrack; | ||
Router.onReady(function () { | ||
var router = getRouter(); | ||
router.onReady(function () { | ||
Vue.nextTick().then(function () { | ||
api.config(config.params); | ||
trackPage({ | ||
to: Router.currentRoute | ||
}); | ||
addConfiguration(); | ||
track(router.currentRoute); | ||
}); | ||
Router.afterEach(function (to, from) { | ||
router.afterEach(function (to, from) { | ||
Vue.nextTick().then(function () { | ||
onBeforeTrack(to, from); | ||
trackPage({ | ||
to: to, | ||
from: from | ||
}); | ||
onAfterTrack(to, from); | ||
if (isFn(onBeforeTrack)) { | ||
onBeforeTrack(to, from); | ||
} | ||
track(to, from); | ||
if (isFn(onAfterTrack)) { | ||
onAfterTrack(to, from); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
var autotrack = function autotrack() { | ||
var Router = getRouter(); | ||
}); | ||
if (!Router) { | ||
return; | ||
} | ||
startRouter(Router); | ||
}; | ||
function _bootstrap () { | ||
if (typeof document === "undefined" || typeof window === "undefined") { | ||
return; | ||
} | ||
var bootstrap = (function () { | ||
var _getOptions = getOptions(), | ||
customResourceURL = _getOptions.customResourceURL, | ||
customPreconnectOrigin = _getOptions.customPreconnectOrigin, | ||
enabled = _getOptions.enabled, | ||
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, | ||
onReady = _getOptions.onReady, | ||
onError = _getOptions.onError, | ||
deferScriptLoad = _getOptions.deferScriptLoad, | ||
disableScriptLoad = _getOptions.disableScriptLoad; | ||
var Router = getRouter(); | ||
var isPageTrackerEnabled = Boolean(pageTrackerEnabled && Router); | ||
var isPageTrackerEnabled = Boolean(pageTrackerEnabled && getRouter()); | ||
registerGlobals(); | ||
if (!enabled) { | ||
optOut(); | ||
} | ||
if (window[globalObjectName] == null) { | ||
window[globalDataLayerName] = window[globalDataLayerName] || []; | ||
window[globalObjectName] = function () { | ||
window[globalDataLayerName].push(arguments); | ||
}; | ||
} | ||
window[globalObjectName]("js", new Date()); | ||
if (isPageTrackerEnabled) { | ||
autotrack(); | ||
addRoutesTracker(); | ||
} else { | ||
api.config(config.params); | ||
addConfiguration(); | ||
} | ||
@@ -489,16 +536,11 @@ | ||
var resource = "".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName); | ||
return loadScript(resource, { | ||
return load("".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName), { | ||
preconnectOrigin: customPreconnectOrigin, | ||
defer: deferScriptLoad | ||
}).then(function () { | ||
var library = window[globalObjectName]; | ||
if (isFn(onReady)) { | ||
onReady(library); | ||
if (onReady) { | ||
onReady(window[globalObjectName]); | ||
} | ||
return library; | ||
}).catch(function (error) { | ||
if (isFn(onError)) { | ||
if (onError) { | ||
onError(error); | ||
@@ -509,86 +551,17 @@ } | ||
}); | ||
} | ||
}); | ||
var Vue; | ||
var Router; | ||
var options = { | ||
customResourceURL: "https://www.googletagmanager.com/gtag/js", | ||
customPreconnectOrigin: "https://www.googletagmanager.com", | ||
pageTrackerTemplate: noop, | ||
onBeforeTrack: noop, | ||
onAfterTrack: noop, | ||
onReady: noop, | ||
onError: noop, | ||
enabled: true, | ||
disableScriptLoad: false, | ||
deferScriptLoad: false, | ||
bootstrap: true, | ||
globalObjectName: "gtag", | ||
globalDataLayerName: "dataLayer", | ||
pageTrackerUseFullPath: false, | ||
pageTrackerEnabled: true, | ||
pageTrackerScreenviewEnabled: false, | ||
pageTrackerSkipSamePath: true, | ||
defaultGroupName: "default", | ||
includes: null, | ||
appName: null, | ||
config: { | ||
id: null, | ||
params: { | ||
send_page_view: false | ||
} | ||
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(); | ||
} | ||
}; | ||
var getOptions = function getOptions() { | ||
return options; | ||
}; | ||
var setOptions = function setOptions(_options) { | ||
return mergeDeep(options, _options); | ||
}; | ||
var getVue = function getVue() { | ||
return Vue; | ||
}; | ||
var getRouter = function getRouter() { | ||
return Router; | ||
}; | ||
var setRouter = function setRouter(_Router) { | ||
return Router = _Router; | ||
}; | ||
function install(_Vue) { | ||
var _options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _Router = arguments.length > 2 ? arguments[2] : undefined; | ||
Vue = _Vue; | ||
Router = _Router; | ||
setOptions(_options); | ||
extend(); | ||
if (!options.bootstrap) { | ||
return; | ||
} | ||
_bootstrap(); | ||
} | ||
var bootstrap = _bootstrap; | ||
var setOptions$1 = setOptions; | ||
var setRouter$1 = setRouter; // export api for usages outside Vuejs context | ||
var query$1 = api.query; | ||
var config$1 = api.config; | ||
var event$1 = api.event; | ||
var pageview$1 = api.pageview; | ||
var screenview$1 = api.screenview; | ||
var customMap$1 = api.customMap; | ||
var time$1 = api.time; | ||
var exception$1 = api.exception; | ||
var linker$1 = api.linker; | ||
var purchase$1 = api.purchase; | ||
var set$1 = api.set; | ||
var optIn$1 = api.optIn; | ||
var optOut$1 = api.optOut; | ||
var refund$1 = api.refund; | ||
export default install; | ||
export { bootstrap, config$1 as config, customMap$1 as customMap, event$1 as event, exception$1 as exception, install, linker$1 as linker, optIn$1 as optIn, optOut$1 as optOut, pageview$1 as pageview, purchase$1 as purchase, query$1 as query, refund$1 as refund, screenview$1 as screenview, set$1 as set, setOptions$1 as setOptions, setRouter$1 as setRouter, time$1 as time }; | ||
export { addRoutesTracker, bootstrap, config, customMap, event, exception, install, linker, optIn, optOut, pageview, purchase, query, refund, screenview, set, setOptions, setRouter, time }; |
@@ -5,2 +5,6 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var Vue = _interopDefault(require('vue')); | ||
function _typeof(obj) { | ||
@@ -71,6 +75,9 @@ "@babel/helpers - typeof"; | ||
var noop = function noop() {}; | ||
function loadScript(url) { | ||
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]; | ||
@@ -80,3 +87,2 @@ var script = document.createElement("script"); | ||
script.src = url; | ||
script.charset = "utf-8"; | ||
script.defer = options.defer; | ||
@@ -95,13 +101,10 @@ | ||
}); | ||
} | ||
function warn(msg) { | ||
console.warn("[vue-gtag] " + msg); | ||
} | ||
function isFn(item) { | ||
return typeof item === "function"; | ||
} | ||
function isObject(item) { | ||
}; | ||
var isFn = function isFn(fn) { | ||
return typeof fn === "function"; | ||
}; | ||
var isObject = function isObject(item) { | ||
return item && _typeof(item) === "object" && !Array.isArray(item); | ||
} | ||
function mergeDeep(target) { | ||
}; | ||
var mergeDeep = function mergeDeep(target) { | ||
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -134,16 +137,76 @@ sources[_key - 1] = arguments[_key]; | ||
return mergeDeep.apply(void 0, [target].concat(sources)); | ||
} | ||
}; | ||
var isBrowser = function isBrowser() { | ||
if (typeof window === "undefined" || typeof document === "undefined") { | ||
return false; | ||
} | ||
function query () { | ||
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 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, | ||
pageTrackerEnabled: true, | ||
enabled: true, | ||
disableScriptLoad: false, | ||
pageTrackerScreenviewEnabled: false, | ||
appName: null, | ||
pageTrackerUseFullPath: false, | ||
pageTrackerSkipSamePath: true, | ||
globalDataLayerName: "dataLayer", | ||
globalObjectName: "gtag", | ||
defaultGroupName: "default", | ||
includes: null, | ||
config: { | ||
id: null, | ||
params: { | ||
send_page_view: false | ||
} | ||
} | ||
}; | ||
}; | ||
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; | ||
if (typeof document === "undefined" || typeof window === "undefined") { | ||
return; | ||
} | ||
(_window = window)[globalObjectName].apply(_window, arguments); | ||
} | ||
}); | ||
@@ -168,14 +231,40 @@ var config = (function () { | ||
var event = (function (name) { | ||
var _params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var assignGlobalProperty = function assignGlobalProperty(id, value) { | ||
window["ga-disable-".concat(id)] = value; | ||
}; | ||
var disable = (function () { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
var _getOptions = getOptions(), | ||
defaultGroupName = _getOptions.defaultGroupName, | ||
config = _getOptions.config, | ||
includes = _getOptions.includes; | ||
var params = _params; | ||
assignGlobalProperty(config.id, value); | ||
if (includes && params.send_to == null) { | ||
params.send_to = includes.map(function (include) { | ||
return include.id; | ||
if (Array.isArray(includes)) { | ||
includes.forEach(function (domain) { | ||
return assignGlobalProperty(domain.id, value); | ||
}); | ||
} | ||
}); | ||
var optOut = (function () { | ||
disable(true); | ||
}); | ||
var optIn = (function () { | ||
disable(false); | ||
}); | ||
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); | ||
@@ -187,70 +276,55 @@ } | ||
var pageview = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var pageview = (function (param) { | ||
var template; | ||
var arg = args[0]; | ||
var params = {}; | ||
if (typeof param === "string") { | ||
template = { | ||
page_path: param | ||
}; | ||
} else if (param.path || param.fullPath) { | ||
var _getOptions = getOptions(), | ||
pageTrackerUseFullPath = _getOptions.pageTrackerUseFullPath; | ||
if (typeof arg === "string") { | ||
params = { | ||
page_path: arg, | ||
page_location: window.location.href | ||
}; | ||
template = _objectSpread2(_objectSpread2({}, param.name && { | ||
page_title: param.name | ||
}), {}, { | ||
page_path: pageTrackerUseFullPath ? param.fullPath : param.path | ||
}); | ||
} else { | ||
params = arg; | ||
template = param; | ||
} | ||
if (params.send_page_view == null) { | ||
params.send_page_view = true; | ||
if (template.page_location == null) { | ||
template.page_location = window.location.href; | ||
} | ||
event("page_view", params); | ||
if (template.send_page_view == null) { | ||
template.send_page_view = true; | ||
} | ||
event("page_view", template); | ||
}); | ||
var screenview = (function () { | ||
var screenview = (function (param) { | ||
var _getOptions = getOptions(), | ||
appName = _getOptions.appName; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
if (!param) { | ||
return; | ||
} | ||
var arg = args[0]; | ||
var params = {}; | ||
var template; | ||
if (typeof arg === "string") { | ||
params = { | ||
screen_name: arg | ||
if (typeof param === "string") { | ||
template = { | ||
screen_name: param | ||
}; | ||
} else { | ||
params = arg; | ||
template = param; | ||
} | ||
if (params.app_name == null) { | ||
params.app_name = appName; | ||
} | ||
if (params.send_page_view == null) { | ||
params.send_page_view = true; | ||
} | ||
event("screen_view", params); | ||
template.app_name = template.app_name || appName; | ||
event("screen_view", template); | ||
}); | ||
var customMap = (function (map) { | ||
config({ | ||
custom_map: map | ||
}); | ||
}); | ||
var time = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
event.apply(void 0, ["timing_complete"].concat(args)); | ||
}); | ||
var exception = (function () { | ||
@@ -268,3 +342,7 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
var purchase = (function () { | ||
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++) { | ||
@@ -274,3 +352,3 @@ args[_key] = arguments[_key]; | ||
event.apply(void 0, ["purchase"].concat(args)); | ||
query.apply(void 0, ["set"].concat(args)); | ||
}); | ||
@@ -286,57 +364,90 @@ | ||
var set = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var purchase = (function (params) { | ||
event("purchase", params); | ||
}); | ||
query.apply(void 0, ["set"].concat(args)); | ||
var customMap = (function (map) { | ||
config({ | ||
custom_map: map | ||
}); | ||
}); | ||
var disable = (function () { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
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(), | ||
includes = _getOptions.includes, | ||
config = _getOptions.config; | ||
enabled = _getOptions.enabled, | ||
globalObjectName = _getOptions.globalObjectName, | ||
globalDataLayerName = _getOptions.globalDataLayerName; | ||
window["ga-disable-".concat(config.id)] = value; | ||
if (window[globalObjectName] == null) { | ||
window[globalDataLayerName] = window[globalDataLayerName] || []; | ||
if (Array.isArray(includes)) { | ||
includes.forEach(function (domain) { | ||
window["ga-disable-".concat(domain.id)] = value; | ||
}); | ||
window[globalObjectName] = function () { | ||
window[globalDataLayerName].push(arguments); | ||
}; | ||
} | ||
}); | ||
var optIn = (function () { | ||
disable(false); | ||
}); | ||
window[globalObjectName]("js", new Date()); | ||
var optOut = (function () { | ||
disable(true); | ||
if (!enabled) { | ||
optOut(); | ||
} | ||
return window[globalObjectName]; | ||
}); | ||
var api = { | ||
query: query, | ||
config: config, | ||
event: event, | ||
pageview: pageview, | ||
screenview: screenview, | ||
customMap: customMap, | ||
time: time, | ||
exception: exception, | ||
linker: linker, | ||
purchase: purchase, | ||
refund: refund, | ||
set: set, | ||
optIn: optIn, | ||
optOut: optOut | ||
var router; | ||
var setRouter = function setRouter(instance) { | ||
router = instance; | ||
}; | ||
var getRouter = function getRouter() { | ||
return router; | ||
}; | ||
var extend = (function () { | ||
var Vue = getVue(); | ||
Vue.$gtag = Vue.prototype.$gtag = api; | ||
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)); | ||
}); | ||
} | ||
}); | ||
var getPageviewTemplate = function getPageviewTemplate() { | ||
var track = (function () { | ||
var to = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -346,13 +457,14 @@ var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _getOptions = getOptions(), | ||
appName = _getOptions.appName, | ||
pageTrackerTemplate = _getOptions.pageTrackerTemplate, | ||
pageTrackerScreenviewEnabled = _getOptions.pageTrackerScreenviewEnabled, | ||
pageTrackerUseFullPath = _getOptions.pageTrackerUseFullPath, | ||
appName = _getOptions.appName; | ||
pageTrackerSkipSamePath = _getOptions.pageTrackerSkipSamePath; | ||
var template; | ||
var customTemplate = pageTrackerTemplate(to, from); | ||
var template = to; | ||
if (customTemplate) { | ||
template = customTemplate; | ||
if (isFn(pageTrackerTemplate)) { | ||
template = pageTrackerTemplate(to, from); | ||
} else if (pageTrackerScreenviewEnabled) { | ||
warn("Missing \"appName\" property inside the plugin options.", appName == null); | ||
warn("Missing \"name\" property in the route with path value \"".concat(to.path, "\"."), to.name == null); | ||
template = { | ||
@@ -362,25 +474,4 @@ app_name: appName, | ||
}; | ||
} else { | ||
template = { | ||
page_title: to.name, | ||
page_path: pageTrackerUseFullPath ? to.fullPath : to.path, | ||
page_location: window.location.href | ||
}; | ||
} | ||
return template; | ||
}; | ||
var trackPage = function trackPage() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$to = _ref.to, | ||
to = _ref$to === void 0 ? {} : _ref$to, | ||
_ref$from = _ref.from, | ||
from = _ref$from === void 0 ? {} : _ref$from, | ||
_ref$params = _ref.params, | ||
params = _ref$params === void 0 ? {} : _ref$params; | ||
var _getOptions2 = getOptions(), | ||
pageTrackerSkipSamePath = _getOptions2.pageTrackerSkipSamePath, | ||
pageTrackerScreenviewEnabled = _getOptions2.pageTrackerScreenviewEnabled; | ||
if (pageTrackerSkipSamePath && to.path === from.path) { | ||
@@ -390,99 +481,57 @@ return; | ||
var newParams = _objectSpread2(_objectSpread2({}, getPageviewTemplate(to, from)), params); | ||
if (pageTrackerScreenviewEnabled && !newParams.app_name) { | ||
warn("To use the screenview, add the appName to the plugin options"); | ||
return; | ||
} | ||
if (pageTrackerScreenviewEnabled && !newParams.screen_name) { | ||
warn("To use the screenview, name your routes"); | ||
return; | ||
} | ||
if (pageTrackerScreenviewEnabled) { | ||
screenview(newParams); | ||
screenview(template); | ||
return; | ||
} | ||
pageview(newParams); | ||
}; | ||
var startRouter = function startRouter(Router) { | ||
var Vue = getVue(); | ||
pageview(template); | ||
}); | ||
var _getOptions3 = getOptions(), | ||
onBeforeTrack = _getOptions3.onBeforeTrack, | ||
onAfterTrack = _getOptions3.onAfterTrack, | ||
config = _getOptions3.config; | ||
/* istanbul ignore next */ | ||
var addRoutesTracker = (function () { | ||
var _getOptions = getOptions(), | ||
onBeforeTrack = _getOptions.onBeforeTrack, | ||
onAfterTrack = _getOptions.onAfterTrack; | ||
Router.onReady(function () { | ||
var router = getRouter(); | ||
router.onReady(function () { | ||
Vue.nextTick().then(function () { | ||
api.config(config.params); | ||
trackPage({ | ||
to: Router.currentRoute | ||
}); | ||
addConfiguration(); | ||
track(router.currentRoute); | ||
}); | ||
Router.afterEach(function (to, from) { | ||
router.afterEach(function (to, from) { | ||
Vue.nextTick().then(function () { | ||
onBeforeTrack(to, from); | ||
trackPage({ | ||
to: to, | ||
from: from | ||
}); | ||
onAfterTrack(to, from); | ||
if (isFn(onBeforeTrack)) { | ||
onBeforeTrack(to, from); | ||
} | ||
track(to, from); | ||
if (isFn(onAfterTrack)) { | ||
onAfterTrack(to, from); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
var autotrack = function autotrack() { | ||
var Router = getRouter(); | ||
}); | ||
if (!Router) { | ||
return; | ||
} | ||
startRouter(Router); | ||
}; | ||
function _bootstrap () { | ||
if (typeof document === "undefined" || typeof window === "undefined") { | ||
return; | ||
} | ||
var bootstrap = (function () { | ||
var _getOptions = getOptions(), | ||
customResourceURL = _getOptions.customResourceURL, | ||
customPreconnectOrigin = _getOptions.customPreconnectOrigin, | ||
enabled = _getOptions.enabled, | ||
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, | ||
onReady = _getOptions.onReady, | ||
onError = _getOptions.onError, | ||
deferScriptLoad = _getOptions.deferScriptLoad, | ||
disableScriptLoad = _getOptions.disableScriptLoad; | ||
var Router = getRouter(); | ||
var isPageTrackerEnabled = Boolean(pageTrackerEnabled && Router); | ||
var isPageTrackerEnabled = Boolean(pageTrackerEnabled && getRouter()); | ||
registerGlobals(); | ||
if (!enabled) { | ||
optOut(); | ||
} | ||
if (window[globalObjectName] == null) { | ||
window[globalDataLayerName] = window[globalDataLayerName] || []; | ||
window[globalObjectName] = function () { | ||
window[globalDataLayerName].push(arguments); | ||
}; | ||
} | ||
window[globalObjectName]("js", new Date()); | ||
if (isPageTrackerEnabled) { | ||
autotrack(); | ||
addRoutesTracker(); | ||
} else { | ||
api.config(config.params); | ||
addConfiguration(); | ||
} | ||
@@ -494,16 +543,11 @@ | ||
var resource = "".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName); | ||
return loadScript(resource, { | ||
return load("".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName), { | ||
preconnectOrigin: customPreconnectOrigin, | ||
defer: deferScriptLoad | ||
}).then(function () { | ||
var library = window[globalObjectName]; | ||
if (isFn(onReady)) { | ||
onReady(library); | ||
if (onReady) { | ||
onReady(window[globalObjectName]); | ||
} | ||
return library; | ||
}).catch(function (error) { | ||
if (isFn(onError)) { | ||
if (onError) { | ||
onError(error); | ||
@@ -514,103 +558,35 @@ } | ||
}); | ||
} | ||
}); | ||
var Vue; | ||
var Router; | ||
var options = { | ||
customResourceURL: "https://www.googletagmanager.com/gtag/js", | ||
customPreconnectOrigin: "https://www.googletagmanager.com", | ||
pageTrackerTemplate: noop, | ||
onBeforeTrack: noop, | ||
onAfterTrack: noop, | ||
onReady: noop, | ||
onError: noop, | ||
enabled: true, | ||
disableScriptLoad: false, | ||
deferScriptLoad: false, | ||
bootstrap: true, | ||
globalObjectName: "gtag", | ||
globalDataLayerName: "dataLayer", | ||
pageTrackerUseFullPath: false, | ||
pageTrackerEnabled: true, | ||
pageTrackerScreenviewEnabled: false, | ||
pageTrackerSkipSamePath: true, | ||
defaultGroupName: "default", | ||
includes: null, | ||
appName: null, | ||
config: { | ||
id: null, | ||
params: { | ||
send_page_view: false | ||
} | ||
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(); | ||
} | ||
}; | ||
var getOptions = function getOptions() { | ||
return options; | ||
}; | ||
var setOptions = function setOptions(_options) { | ||
return mergeDeep(options, _options); | ||
}; | ||
var getVue = function getVue() { | ||
return Vue; | ||
}; | ||
var getRouter = function getRouter() { | ||
return Router; | ||
}; | ||
var setRouter = function setRouter(_Router) { | ||
return Router = _Router; | ||
}; | ||
function install(_Vue) { | ||
var _options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _Router = arguments.length > 2 ? arguments[2] : undefined; | ||
Vue = _Vue; | ||
Router = _Router; | ||
setOptions(_options); | ||
extend(); | ||
if (!options.bootstrap) { | ||
return; | ||
} | ||
_bootstrap(); | ||
} | ||
var bootstrap = _bootstrap; | ||
var setOptions$1 = setOptions; | ||
var setRouter$1 = setRouter; // export api for usages outside Vuejs context | ||
var query$1 = api.query; | ||
var config$1 = api.config; | ||
var event$1 = api.event; | ||
var pageview$1 = api.pageview; | ||
var screenview$1 = api.screenview; | ||
var customMap$1 = api.customMap; | ||
var time$1 = api.time; | ||
var exception$1 = api.exception; | ||
var linker$1 = api.linker; | ||
var purchase$1 = api.purchase; | ||
var set$1 = api.set; | ||
var optIn$1 = api.optIn; | ||
var optOut$1 = api.optOut; | ||
var refund$1 = api.refund; | ||
exports.addRoutesTracker = addRoutesTracker; | ||
exports.bootstrap = bootstrap; | ||
exports.config = config$1; | ||
exports.customMap = customMap$1; | ||
exports.config = config; | ||
exports.customMap = customMap; | ||
exports.default = install; | ||
exports.event = event$1; | ||
exports.exception = exception$1; | ||
exports.event = event; | ||
exports.exception = exception; | ||
exports.install = install; | ||
exports.linker = linker$1; | ||
exports.optIn = optIn$1; | ||
exports.optOut = optOut$1; | ||
exports.pageview = pageview$1; | ||
exports.purchase = purchase$1; | ||
exports.query = query$1; | ||
exports.refund = refund$1; | ||
exports.screenview = screenview$1; | ||
exports.set = set$1; | ||
exports.setOptions = setOptions$1; | ||
exports.setRouter = setRouter$1; | ||
exports.time = time$1; | ||
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; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.VueGtag = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
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) { | ||
@@ -72,6 +74,9 @@ "@babel/helpers - typeof"; | ||
var noop = function noop() {}; | ||
function loadScript(url) { | ||
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]; | ||
@@ -81,3 +86,2 @@ var script = document.createElement("script"); | ||
script.src = url; | ||
script.charset = "utf-8"; | ||
script.defer = options.defer; | ||
@@ -96,13 +100,10 @@ | ||
}); | ||
} | ||
function warn(msg) { | ||
console.warn("[vue-gtag] " + msg); | ||
} | ||
function isFn(item) { | ||
return typeof item === "function"; | ||
} | ||
function isObject(item) { | ||
}; | ||
var isFn = function isFn(fn) { | ||
return typeof fn === "function"; | ||
}; | ||
var isObject = function isObject(item) { | ||
return item && _typeof(item) === "object" && !Array.isArray(item); | ||
} | ||
function mergeDeep(target) { | ||
}; | ||
var mergeDeep = function mergeDeep(target) { | ||
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -135,16 +136,76 @@ sources[_key - 1] = arguments[_key]; | ||
return mergeDeep.apply(void 0, [target].concat(sources)); | ||
} | ||
}; | ||
var isBrowser = function isBrowser() { | ||
if (typeof window === "undefined" || typeof document === "undefined") { | ||
return false; | ||
} | ||
function query () { | ||
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 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, | ||
pageTrackerEnabled: true, | ||
enabled: true, | ||
disableScriptLoad: false, | ||
pageTrackerScreenviewEnabled: false, | ||
appName: null, | ||
pageTrackerUseFullPath: false, | ||
pageTrackerSkipSamePath: true, | ||
globalDataLayerName: "dataLayer", | ||
globalObjectName: "gtag", | ||
defaultGroupName: "default", | ||
includes: null, | ||
config: { | ||
id: null, | ||
params: { | ||
send_page_view: false | ||
} | ||
} | ||
}; | ||
}; | ||
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; | ||
if (typeof document === "undefined" || typeof window === "undefined") { | ||
return; | ||
} | ||
(_window = window)[globalObjectName].apply(_window, arguments); | ||
} | ||
}); | ||
@@ -169,14 +230,40 @@ var config = (function () { | ||
var event = (function (name) { | ||
var _params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var assignGlobalProperty = function assignGlobalProperty(id, value) { | ||
window["ga-disable-".concat(id)] = value; | ||
}; | ||
var disable = (function () { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
var _getOptions = getOptions(), | ||
defaultGroupName = _getOptions.defaultGroupName, | ||
config = _getOptions.config, | ||
includes = _getOptions.includes; | ||
var params = _params; | ||
assignGlobalProperty(config.id, value); | ||
if (includes && params.send_to == null) { | ||
params.send_to = includes.map(function (include) { | ||
return include.id; | ||
if (Array.isArray(includes)) { | ||
includes.forEach(function (domain) { | ||
return assignGlobalProperty(domain.id, value); | ||
}); | ||
} | ||
}); | ||
var optOut = (function () { | ||
disable(true); | ||
}); | ||
var optIn = (function () { | ||
disable(false); | ||
}); | ||
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); | ||
@@ -188,70 +275,55 @@ } | ||
var pageview = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var pageview = (function (param) { | ||
var template; | ||
var arg = args[0]; | ||
var params = {}; | ||
if (typeof param === "string") { | ||
template = { | ||
page_path: param | ||
}; | ||
} else if (param.path || param.fullPath) { | ||
var _getOptions = getOptions(), | ||
pageTrackerUseFullPath = _getOptions.pageTrackerUseFullPath; | ||
if (typeof arg === "string") { | ||
params = { | ||
page_path: arg, | ||
page_location: window.location.href | ||
}; | ||
template = _objectSpread2(_objectSpread2({}, param.name && { | ||
page_title: param.name | ||
}), {}, { | ||
page_path: pageTrackerUseFullPath ? param.fullPath : param.path | ||
}); | ||
} else { | ||
params = arg; | ||
template = param; | ||
} | ||
if (params.send_page_view == null) { | ||
params.send_page_view = true; | ||
if (template.page_location == null) { | ||
template.page_location = window.location.href; | ||
} | ||
event("page_view", params); | ||
if (template.send_page_view == null) { | ||
template.send_page_view = true; | ||
} | ||
event("page_view", template); | ||
}); | ||
var screenview = (function () { | ||
var screenview = (function (param) { | ||
var _getOptions = getOptions(), | ||
appName = _getOptions.appName; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
if (!param) { | ||
return; | ||
} | ||
var arg = args[0]; | ||
var params = {}; | ||
var template; | ||
if (typeof arg === "string") { | ||
params = { | ||
screen_name: arg | ||
if (typeof param === "string") { | ||
template = { | ||
screen_name: param | ||
}; | ||
} else { | ||
params = arg; | ||
template = param; | ||
} | ||
if (params.app_name == null) { | ||
params.app_name = appName; | ||
} | ||
if (params.send_page_view == null) { | ||
params.send_page_view = true; | ||
} | ||
event("screen_view", params); | ||
template.app_name = template.app_name || appName; | ||
event("screen_view", template); | ||
}); | ||
var customMap = (function (map) { | ||
config({ | ||
custom_map: map | ||
}); | ||
}); | ||
var time = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
event.apply(void 0, ["timing_complete"].concat(args)); | ||
}); | ||
var exception = (function () { | ||
@@ -269,3 +341,7 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
var purchase = (function () { | ||
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++) { | ||
@@ -275,3 +351,3 @@ args[_key] = arguments[_key]; | ||
event.apply(void 0, ["purchase"].concat(args)); | ||
query.apply(void 0, ["set"].concat(args)); | ||
}); | ||
@@ -287,57 +363,90 @@ | ||
var set = (function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var purchase = (function (params) { | ||
event("purchase", params); | ||
}); | ||
query.apply(void 0, ["set"].concat(args)); | ||
var customMap = (function (map) { | ||
config({ | ||
custom_map: map | ||
}); | ||
}); | ||
var disable = (function () { | ||
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
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(), | ||
includes = _getOptions.includes, | ||
config = _getOptions.config; | ||
enabled = _getOptions.enabled, | ||
globalObjectName = _getOptions.globalObjectName, | ||
globalDataLayerName = _getOptions.globalDataLayerName; | ||
window["ga-disable-".concat(config.id)] = value; | ||
if (window[globalObjectName] == null) { | ||
window[globalDataLayerName] = window[globalDataLayerName] || []; | ||
if (Array.isArray(includes)) { | ||
includes.forEach(function (domain) { | ||
window["ga-disable-".concat(domain.id)] = value; | ||
}); | ||
window[globalObjectName] = function () { | ||
window[globalDataLayerName].push(arguments); | ||
}; | ||
} | ||
}); | ||
var optIn = (function () { | ||
disable(false); | ||
}); | ||
window[globalObjectName]("js", new Date()); | ||
var optOut = (function () { | ||
disable(true); | ||
if (!enabled) { | ||
optOut(); | ||
} | ||
return window[globalObjectName]; | ||
}); | ||
var api = { | ||
query: query, | ||
config: config, | ||
event: event, | ||
pageview: pageview, | ||
screenview: screenview, | ||
customMap: customMap, | ||
time: time, | ||
exception: exception, | ||
linker: linker, | ||
purchase: purchase, | ||
refund: refund, | ||
set: set, | ||
optIn: optIn, | ||
optOut: optOut | ||
var router; | ||
var setRouter = function setRouter(instance) { | ||
router = instance; | ||
}; | ||
var getRouter = function getRouter() { | ||
return router; | ||
}; | ||
var extend = (function () { | ||
var Vue = getVue(); | ||
Vue.$gtag = Vue.prototype.$gtag = api; | ||
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)); | ||
}); | ||
} | ||
}); | ||
var getPageviewTemplate = function getPageviewTemplate() { | ||
var track = (function () { | ||
var to = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -347,13 +456,14 @@ var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _getOptions = getOptions(), | ||
appName = _getOptions.appName, | ||
pageTrackerTemplate = _getOptions.pageTrackerTemplate, | ||
pageTrackerScreenviewEnabled = _getOptions.pageTrackerScreenviewEnabled, | ||
pageTrackerUseFullPath = _getOptions.pageTrackerUseFullPath, | ||
appName = _getOptions.appName; | ||
pageTrackerSkipSamePath = _getOptions.pageTrackerSkipSamePath; | ||
var template; | ||
var customTemplate = pageTrackerTemplate(to, from); | ||
var template = to; | ||
if (customTemplate) { | ||
template = customTemplate; | ||
if (isFn(pageTrackerTemplate)) { | ||
template = pageTrackerTemplate(to, from); | ||
} else if (pageTrackerScreenviewEnabled) { | ||
warn("Missing \"appName\" property inside the plugin options.", appName == null); | ||
warn("Missing \"name\" property in the route with path value \"".concat(to.path, "\"."), to.name == null); | ||
template = { | ||
@@ -363,25 +473,4 @@ app_name: appName, | ||
}; | ||
} else { | ||
template = { | ||
page_title: to.name, | ||
page_path: pageTrackerUseFullPath ? to.fullPath : to.path, | ||
page_location: window.location.href | ||
}; | ||
} | ||
return template; | ||
}; | ||
var trackPage = function trackPage() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$to = _ref.to, | ||
to = _ref$to === void 0 ? {} : _ref$to, | ||
_ref$from = _ref.from, | ||
from = _ref$from === void 0 ? {} : _ref$from, | ||
_ref$params = _ref.params, | ||
params = _ref$params === void 0 ? {} : _ref$params; | ||
var _getOptions2 = getOptions(), | ||
pageTrackerSkipSamePath = _getOptions2.pageTrackerSkipSamePath, | ||
pageTrackerScreenviewEnabled = _getOptions2.pageTrackerScreenviewEnabled; | ||
if (pageTrackerSkipSamePath && to.path === from.path) { | ||
@@ -391,99 +480,57 @@ return; | ||
var newParams = _objectSpread2(_objectSpread2({}, getPageviewTemplate(to, from)), params); | ||
if (pageTrackerScreenviewEnabled && !newParams.app_name) { | ||
warn("To use the screenview, add the appName to the plugin options"); | ||
return; | ||
} | ||
if (pageTrackerScreenviewEnabled && !newParams.screen_name) { | ||
warn("To use the screenview, name your routes"); | ||
return; | ||
} | ||
if (pageTrackerScreenviewEnabled) { | ||
screenview(newParams); | ||
screenview(template); | ||
return; | ||
} | ||
pageview(newParams); | ||
}; | ||
var startRouter = function startRouter(Router) { | ||
var Vue = getVue(); | ||
pageview(template); | ||
}); | ||
var _getOptions3 = getOptions(), | ||
onBeforeTrack = _getOptions3.onBeforeTrack, | ||
onAfterTrack = _getOptions3.onAfterTrack, | ||
config = _getOptions3.config; | ||
/* istanbul ignore next */ | ||
var addRoutesTracker = (function () { | ||
var _getOptions = getOptions(), | ||
onBeforeTrack = _getOptions.onBeforeTrack, | ||
onAfterTrack = _getOptions.onAfterTrack; | ||
Router.onReady(function () { | ||
var router = getRouter(); | ||
router.onReady(function () { | ||
Vue.nextTick().then(function () { | ||
api.config(config.params); | ||
trackPage({ | ||
to: Router.currentRoute | ||
}); | ||
addConfiguration(); | ||
track(router.currentRoute); | ||
}); | ||
Router.afterEach(function (to, from) { | ||
router.afterEach(function (to, from) { | ||
Vue.nextTick().then(function () { | ||
onBeforeTrack(to, from); | ||
trackPage({ | ||
to: to, | ||
from: from | ||
}); | ||
onAfterTrack(to, from); | ||
if (isFn(onBeforeTrack)) { | ||
onBeforeTrack(to, from); | ||
} | ||
track(to, from); | ||
if (isFn(onAfterTrack)) { | ||
onAfterTrack(to, from); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
var autotrack = function autotrack() { | ||
var Router = getRouter(); | ||
}); | ||
if (!Router) { | ||
return; | ||
} | ||
startRouter(Router); | ||
}; | ||
function _bootstrap () { | ||
if (typeof document === "undefined" || typeof window === "undefined") { | ||
return; | ||
} | ||
var bootstrap = (function () { | ||
var _getOptions = getOptions(), | ||
customResourceURL = _getOptions.customResourceURL, | ||
customPreconnectOrigin = _getOptions.customPreconnectOrigin, | ||
enabled = _getOptions.enabled, | ||
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, | ||
onReady = _getOptions.onReady, | ||
onError = _getOptions.onError, | ||
deferScriptLoad = _getOptions.deferScriptLoad, | ||
disableScriptLoad = _getOptions.disableScriptLoad; | ||
var Router = getRouter(); | ||
var isPageTrackerEnabled = Boolean(pageTrackerEnabled && Router); | ||
var isPageTrackerEnabled = Boolean(pageTrackerEnabled && getRouter()); | ||
registerGlobals(); | ||
if (!enabled) { | ||
optOut(); | ||
} | ||
if (window[globalObjectName] == null) { | ||
window[globalDataLayerName] = window[globalDataLayerName] || []; | ||
window[globalObjectName] = function () { | ||
window[globalDataLayerName].push(arguments); | ||
}; | ||
} | ||
window[globalObjectName]("js", new Date()); | ||
if (isPageTrackerEnabled) { | ||
autotrack(); | ||
addRoutesTracker(); | ||
} else { | ||
api.config(config.params); | ||
addConfiguration(); | ||
} | ||
@@ -495,16 +542,11 @@ | ||
var resource = "".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName); | ||
return loadScript(resource, { | ||
return load("".concat(customResourceURL, "?id=").concat(config.id, "&l=").concat(globalDataLayerName), { | ||
preconnectOrigin: customPreconnectOrigin, | ||
defer: deferScriptLoad | ||
}).then(function () { | ||
var library = window[globalObjectName]; | ||
if (isFn(onReady)) { | ||
onReady(library); | ||
if (onReady) { | ||
onReady(window[globalObjectName]); | ||
} | ||
return library; | ||
}).catch(function (error) { | ||
if (isFn(onError)) { | ||
if (onError) { | ||
onError(error); | ||
@@ -515,104 +557,36 @@ } | ||
}); | ||
} | ||
}); | ||
var Vue; | ||
var Router; | ||
var options = { | ||
customResourceURL: "https://www.googletagmanager.com/gtag/js", | ||
customPreconnectOrigin: "https://www.googletagmanager.com", | ||
pageTrackerTemplate: noop, | ||
onBeforeTrack: noop, | ||
onAfterTrack: noop, | ||
onReady: noop, | ||
onError: noop, | ||
enabled: true, | ||
disableScriptLoad: false, | ||
deferScriptLoad: false, | ||
bootstrap: true, | ||
globalObjectName: "gtag", | ||
globalDataLayerName: "dataLayer", | ||
pageTrackerUseFullPath: false, | ||
pageTrackerEnabled: true, | ||
pageTrackerScreenviewEnabled: false, | ||
pageTrackerSkipSamePath: true, | ||
defaultGroupName: "default", | ||
includes: null, | ||
appName: null, | ||
config: { | ||
id: null, | ||
params: { | ||
send_page_view: false | ||
} | ||
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(); | ||
} | ||
}; | ||
var getOptions = function getOptions() { | ||
return options; | ||
}; | ||
var setOptions = function setOptions(_options) { | ||
return mergeDeep(options, _options); | ||
}; | ||
var getVue = function getVue() { | ||
return Vue; | ||
}; | ||
var getRouter = function getRouter() { | ||
return Router; | ||
}; | ||
var setRouter = function setRouter(_Router) { | ||
return Router = _Router; | ||
}; | ||
function install(_Vue) { | ||
var _options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _Router = arguments.length > 2 ? arguments[2] : undefined; | ||
Vue = _Vue; | ||
Router = _Router; | ||
setOptions(_options); | ||
extend(); | ||
if (!options.bootstrap) { | ||
return; | ||
} | ||
_bootstrap(); | ||
} | ||
var bootstrap = _bootstrap; | ||
var setOptions$1 = setOptions; | ||
var setRouter$1 = setRouter; // export api for usages outside Vuejs context | ||
var query$1 = api.query; | ||
var config$1 = api.config; | ||
var event$1 = api.event; | ||
var pageview$1 = api.pageview; | ||
var screenview$1 = api.screenview; | ||
var customMap$1 = api.customMap; | ||
var time$1 = api.time; | ||
var exception$1 = api.exception; | ||
var linker$1 = api.linker; | ||
var purchase$1 = api.purchase; | ||
var set$1 = api.set; | ||
var optIn$1 = api.optIn; | ||
var optOut$1 = api.optOut; | ||
var refund$1 = api.refund; | ||
exports.addRoutesTracker = addRoutesTracker; | ||
exports.bootstrap = bootstrap; | ||
exports.config = config$1; | ||
exports.customMap = customMap$1; | ||
exports.config = config; | ||
exports.customMap = customMap; | ||
exports.default = install; | ||
exports.event = event$1; | ||
exports.exception = exception$1; | ||
exports.event = event; | ||
exports.exception = exception; | ||
exports.install = install; | ||
exports.linker = linker$1; | ||
exports.optIn = optIn$1; | ||
exports.optOut = optOut$1; | ||
exports.pageview = pageview$1; | ||
exports.purchase = purchase$1; | ||
exports.query = query$1; | ||
exports.refund = refund$1; | ||
exports.screenview = screenview$1; | ||
exports.set = set$1; | ||
exports.setOptions = setOptions$1; | ||
exports.setRouter = setRouter$1; | ||
exports.time = time$1; | ||
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; | ||
@@ -619,0 +593,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).VueGtag={})}(this,(function(e){"use strict";function n(e){return(n="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 t(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function r(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 o(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?r(Object(o),!0).forEach((function(n){t(e,n,o[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):r(Object(o)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(o,n))}))}return e}var a=function(){};function i(e){console.warn("[vue-gtag] "+e)}function c(e){return"function"==typeof e}function u(e){return e&&"object"===n(e)&&!Array.isArray(e)}function p(){var e,n=T(),t=n.globalObjectName;"undefined"!=typeof document&&"undefined"!=typeof window&&(e=window)[t].apply(e,arguments)}var f,l,d=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var r=T(),o=r.config,a=r.includes;p.apply(void 0,["config",o.id].concat(n)),Array.isArray(a)&&a.forEach((function(e){p.apply(void 0,["config",e.id].concat(n))}))},s=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=T(),r=t.defaultGroupName,o=t.includes,a=n;o&&null==a.send_to&&(a.send_to=o.map((function(e){return e.id})).concat(r)),p("event",e,a)},g=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var r=n[0],o={};null==(o="string"==typeof r?{page_path:r,page_location:window.location.href}:r).send_page_view&&(o.send_page_view=!0),s("page_view",o)},v=function(){for(var e=T(),n=e.appName,t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];var a=r[0],i={};null==(i="string"==typeof a?{screen_name:a}:a).app_name&&(i.app_name=n),null==i.send_page_view&&(i.send_page_view=!0),s("screen_view",i)},m=function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],n=T(),t=n.includes,r=n.config;window["ga-disable-".concat(r.id)]=e,Array.isArray(t)&&t.forEach((function(n){window["ga-disable-".concat(n.id)]=e}))},y=function(){m(!0)},w={query:p,config:d,event:s,pageview:g,screenview:v,customMap:function(e){d({custom_map:e})},time:function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];s.apply(void 0,["timing_complete"].concat(n))},exception:function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];s.apply(void 0,["exception"].concat(n))},linker:function(e){d("linker",e)},purchase:function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];s.apply(void 0,["purchase"].concat(n))},refund:function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];s.apply(void 0,["refund"].concat(n))},set:function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];p.apply(void 0,["set"].concat(n))},optIn:function(){m(!1)},optOut:y},h=function(){var e=S();e.$gtag=e.prototype.$gtag=w},b=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=T(),r=t.pageTrackerTemplate,o=t.pageTrackerScreenviewEnabled,a=t.pageTrackerUseFullPath,i=t.appName,c=r(e,n);return c||(o?{app_name:i,screen_name:e.name}:{page_title:e.name,page_path:a?e.fullPath:e.path,page_location:window.location.href})},O=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.to,t=void 0===n?{}:n,r=e.from,a=void 0===r?{}:r,c=e.params,u=void 0===c?{}:c,p=T(),f=p.pageTrackerSkipSamePath,l=p.pageTrackerScreenviewEnabled;if(!f||t.path!==a.path){var d=o(o({},b(t,a)),u);!l||d.app_name?!l||d.screen_name?l?v(d):g(d):i("To use the screenview, name your routes"):i("To use the screenview, add the appName to the plugin options")}},_=function(){var e=A();e&&function(e){var n=S(),t=T(),r=t.onBeforeTrack,o=t.onAfterTrack,a=t.config;e.onReady((function(){n.nextTick().then((function(){w.config(a.params),O({to:e.currentRoute})})),e.afterEach((function(e,t){n.nextTick().then((function(){r(e,t),O({to:e,from:t}),o(e,t)}))}))}))}(e)};function k(){if("undefined"!=typeof document&&"undefined"!=typeof window){var e=T(),n=e.customResourceURL,t=e.customPreconnectOrigin,r=e.enabled,o=e.globalObjectName,a=e.globalDataLayerName,i=e.config,u=e.pageTrackerEnabled,p=e.onReady,f=e.onError,l=e.deferScriptLoad,d=e.disableScriptLoad,s=A(),g=Boolean(u&&s);if(r||y(),null==window[o]&&(window[a]=window[a]||[],window[o]=function(){window[a].push(arguments)}),window[o]("js",new Date),g?_():w.config(i.params),!d)return function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return new Promise((function(t,r){var o=document.head||document.getElementsByTagName("head")[0],a=document.createElement("script");if(a.async=!0,a.src=e,a.charset="utf-8",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(n,"?id=").concat(i.id,"&l=").concat(a),{preconnectOrigin:t,defer:l}).then((function(){var e=window[o];return c(p)&&p(e),e})).catch((function(e){return c(f)&&f(e),e}))}}var j={customResourceURL:"https://www.googletagmanager.com/gtag/js",customPreconnectOrigin:"https://www.googletagmanager.com",pageTrackerTemplate:a,onBeforeTrack:a,onAfterTrack:a,onReady:a,onError:a,enabled:!0,disableScriptLoad:!1,deferScriptLoad:!1,bootstrap:!0,globalObjectName:"gtag",globalDataLayerName:"dataLayer",pageTrackerUseFullPath:!1,pageTrackerEnabled:!0,pageTrackerScreenviewEnabled:!1,pageTrackerSkipSamePath:!0,defaultGroupName:"default",includes:null,appName:null,config:{id:null,params:{send_page_view:!1}}},T=function(){return j},P=function(e){return function e(n){for(var r=arguments.length,o=new Array(r>1?r-1:0),a=1;a<r;a++)o[a-1]=arguments[a];if(!o.length)return n;var i=o.shift();if(u(n)&&u(i)){for(var c in i)u(i[c])?(n[c]||Object.assign(n,t({},c,{})),e(n[c],i[c])):Object.assign(n,t({},c,i[c]));return e.apply(void 0,[n].concat(o))}}(j,e)},S=function(){return f},A=function(){return l};function E(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2?arguments[2]:void 0;f=e,l=t,P(n),h(),j.bootstrap&&k()}var N=k,x=P,L=function(e){return l=e},R=w.query,D=w.config,B=w.event,M=w.pageview,U=w.screenview,q=w.customMap,G=w.time,I=w.exception,C=w.linker,F=w.purchase,$=w.set,V=w.optIn,z=w.optOut,H=w.refund;e.bootstrap=N,e.config=D,e.customMap=q,e.default=E,e.event=B,e.exception=I,e.install=E,e.linker=C,e.optIn=V,e.optOut=z,e.pageview=M,e.purchase=F,e.query=R,e.refund=H,e.screenview=U,e.set=$,e.setOptions=x,e.setRouter=L,e.time=G,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!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;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(Object(t),!0).forEach((function(n){r(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;var i,c=function(e){return"function"==typeof e},u=function(e){return e&&"object"===t(e)&&!Array.isArray(e)},p=function e(n){for(var t=arguments.length,o=new Array(t>1?t-1:0),a=1;a<t;a++)o[a-1]=arguments[a];if(!o.length)return n;var i=o.shift();if(u(n)&&u(i)){for(var c in i)u(i[c])?(n[c]||Object.assign(n,r({},c,{})),e(n[c],i[c])):Object.assign(n,r({},c,i[c]));return e.apply(void 0,[n].concat(o))}},f=function(){return"undefined"!=typeof window&&"undefined"!=typeof document},l=function(e){f()},d={},s=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,pageTrackerEnabled:!0,enabled:!0,disableScriptLoad:!1,pageTrackerScreenviewEnabled:!1,appName:null,pageTrackerUseFullPath:!1,pageTrackerSkipSamePath:!0,globalDataLayerName:"dataLayer",globalObjectName:"gtag",defaultGroupName:"default",includes:null,config:{id:null,params:{send_page_view:!1}}};d=p(n,e)},g=function(){return d},y=function(){var e;if(f()){var n=g(),t=n.globalObjectName;(e=window)[t].apply(e,arguments)}},m=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];var r=g(),o=r.config,a=r.includes;y.apply(void 0,["config",o.id].concat(n)),Array.isArray(a)&&a.forEach((function(e){y.apply(void 0,["config",e.id].concat(n))}))},v=function(e,n){window["ga-disable-".concat(e)]=n},h=function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],n=g(),t=n.config,r=n.includes;v(t.id,e),Array.isArray(r)&&r.forEach((function(n){return v(n.id,e)}))},w=function(){h(!0)},b=function(){h(!1)},O=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=g(),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)),y("event",e,n)},_=function(e){var n;if("string"==typeof e)n={page_path:e};else if(e.path||e.fullPath){var t=g().pageTrackerUseFullPath;n=a(a({},e.name&&{page_title:e.name}),{},{page_path:t?e.fullPath:e.path})}else n=e;null==n.page_location&&(n.page_location=window.location.href),null==n.send_page_view&&(n.send_page_view=!0),O("page_view",n)},j=function(e){var n,t=g().appName;e&&((n="string"==typeof e?{screen_name:e}:e).app_name=n.app_name||t,O("screen_view",n))},k=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];O.apply(void 0,["exception"].concat(n))},P=function(e){m("linker",e)},T=function(e){O("timing_complete",e)},A=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];y.apply(void 0,["set"].concat(n))},S=function(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];O.apply(void 0,["refund"].concat(n))},E=function(e){O("purchase",e)},N=function(e){m({custom_map:e})},L=Object.freeze({__proto__:null,query:y,config:m,optOut:w,optIn:b,pageview:_,screenview:j,exception:k,linker:P,time:T,set:A,refund:S,purchase:E,customMap:N,event:O}),R=function(e){return e.$gtag=e.prototype.$gtag=L},x=function(e){i=e},D=function(){return i},M=function(e){return a({send_page_view:!1},e)},B=function(){var e=g(),n=e.config,t=e.includes;y("config",n.id,M(n.params)),Array.isArray(t)&&t.forEach((function(e){y("config",e.id,M(e.params))}))},U=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=g(),r=t.appName,o=t.pageTrackerTemplate,a=t.pageTrackerScreenviewEnabled,i=t.pageTrackerSkipSamePath,u=e;c(o)?u=o(e,n):a&&(l('Missing "appName" property inside the plugin options.',null==r),l('Missing "name" property in the route with path value "'.concat(e.path,'".'),null==e.name),u={app_name:r,screen_name:e.name}),i&&e.path===n.path||(a?j(u):_(u))},q=function(){var e=g(),t=e.onBeforeTrack,r=e.onAfterTrack,o=D();o.onReady((function(){n.nextTick().then((function(){B(),U(o.currentRoute)})),o.afterEach((function(e,o){n.nextTick().then((function(){c(t)&&t(e,o),U(e,o),c(r)&&r(e,o)}))}))}))},G=function(){var e=g(),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,l=e.disableScriptLoad,d=Boolean(p&&D());if(function(){if(f()){var e=g(),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||w(),window[t]}}(),d?q():B(),!l)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}))},C=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2?arguments[2]:void 0;R(e),s(n),x(t),g().bootstrap&&G()};e.addRoutesTracker=q,e.bootstrap=G,e.config=m,e.customMap=N,e.default=C,e.event=O,e.exception=k,e.install=C,e.linker=P,e.optIn=b,e.optOut=w,e.pageview=_,e.purchase=E,e.query=y,e.refund=S,e.screenview=j,e.set=A,e.setOptions=s,e.setRouter=x,e.time=T,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=vue-gtag.umd.min.js.map |
{ | ||
"name": "vue-gtag", | ||
"description": "Global Site Tag (gtag.js) plugin for Vue", | ||
"version": "1.14.0", | ||
"version": "1.14.1", | ||
"author": { | ||
@@ -19,12 +19,12 @@ "name": "Matteo Gabriele", | ||
"build": "bili", | ||
"dev": "bili --config bili.config.dev.js --watch", | ||
"dev": "NODE_ENV=dev bili --watch", | ||
"lint": "eslint --ext .js .", | ||
"lint:fix": "yarn lint --fix", | ||
"test": "jest", | ||
"test:ci": "jest --coverage --bail --runInBand --verbose=false", | ||
"coverage": "jest --coverage", | ||
"coverage:html": "jest --coverage --coverageReporters=html", | ||
"coverage:text": "jest --coverage --coverageReporters=text", | ||
"coverage:lcov": "jest --coverage --coverageReporters=lcov", | ||
"prepublishOnly": "yarn lint && yarn test && yarn build", | ||
"test": "TZ=UTC jest", | ||
"test:ci": "TZ=UTC jest --coverage --bail --runInBand --verbose=false", | ||
"coverage": "TZ=UTC jest --coverage", | ||
"coverage:html": "TZ=UTC jest --coverage --coverageReporters=html", | ||
"coverage:text": "TZ=UTC jest --coverage --coverageReporters=text", | ||
"coverage:lcov": "TZ=UTC jest --coverage --coverageReporters=lcov", | ||
"prepublishOnly": "TZ=UTC yarn lint && yarn test && yarn build", | ||
"semantic-release": "semantic-release" | ||
@@ -38,2 +38,11 @@ }, | ||
"jest": { | ||
"setupFiles": [ | ||
"<rootDir>/jest/init.js" | ||
], | ||
"testMatch": [ | ||
"**/test/**/*.spec.js" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"jest-extended" | ||
], | ||
"collectCoverage": true, | ||
@@ -74,2 +83,5 @@ "coverageReporters": [ | ||
"homepage": "https://github.com/MatteoGabriele/vue-gtag#readme", | ||
"peerDependencies": { | ||
"vue": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -82,2 +94,3 @@ "@babel/core": "^7.7.2", | ||
"commitizen": "^4.0.3", | ||
"core-js": "^3.10.1", | ||
"cz-conventional-changelog": "^3.0.2", | ||
@@ -92,5 +105,10 @@ "del-cli": "^3.0.0", | ||
"jest": "^26.0.1", | ||
"jest-extended": "^0.11.5", | ||
"mockdate": "^3.0.5", | ||
"prettier": "^2.0.5", | ||
"regenerator-runtime": "^0.13.7", | ||
"rollup-plugin-alias": "^2.2.0", | ||
"rollup-plugin-resolve": "^0.0.1-predev.1", | ||
"semantic-release": "^15.13.31", | ||
"vue": "^2.6.10", | ||
"vue": "^2.6.12", | ||
"vue-router": "^3.1.3", | ||
@@ -97,0 +115,0 @@ "vue-template-compiler": "^2.6.10" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84290
1
26
1715
1
2