UNPKG

vue-gtag-next

Version:
3 lines (2 loc) 5.93 kB
!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";var a=function(){return"undefined"!=typeof document&&"undefined"!=typeof window},t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Object.keys(n).forEach((function(a){e[a]=n[a]}))},o=n.reactive({property:null,isEnabled:!0,disableScriptLoader:!1,useDebugger:!1,globalObjectName:"gtag",dataLayerName:"dataLayer",resourceURL:"https://www.googletagmanager.com/gtag/js",preconnectOrigin:"https://www.googletagmanager.com",customResource:null,appName:null,appId:null,appVersion:null}),r=function(){return n.toRefs(o)},i=n.computed((function(){var e=r().property;if(e.value)return Array.isArray(e.value)?e.value.find((function(e){return!0===e.default}))||e.value[0]:e.value})),u=n.computed((function(){var e=r().property;return Boolean(e.value&&null!==e.value.id)})),l=n.computed((function(){var e=r().property;return Array.isArray(e.value)?e.value:[e.value]})),c=n.computed((function(){var e=r().isEnabled,n=i.value;return Boolean(n&&n.id&&e.value)})),v=function(){var e;if(a()){for(var n=r(),t=n.globalObjectName,o=n.useDebugger,i=arguments.length,u=new Array(i),l=0;l<i;l++)u[l]=arguments[l];o.value&&console.warn("[vue-gtag] Debugger:",u),(e=window)[t.value].apply(e,u)}},p=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];l.value.forEach((function(e){v.apply(void 0,["config",e.id].concat(n))}))},f=function(e){p({custom_map:e})},d=function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];a()&&l.value.forEach((function(n){window["ga-disable-".concat(n.id)]=e}))},s=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=Object.assign({},n);!a.send_to&&l.value.length>1&&(a.send_to=l.value.map((function(e){return e.id}))),v("event",e,a)},g=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];s.apply(void 0,["exception"].concat(n))},w=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];p.apply(void 0,["linker"].concat(n))},m=function(e){var n={};void 0===(n="string"==typeof e?{page_path:e,page_location:window.location.href}:e).send_page_view&&(n.send_page_view=!0),s("page_view",n)},h=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];s.apply(void 0,["purchase"].concat(n))},y=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];s.apply(void 0,["refund"].concat(n))},_=function(){for(var e=r(),n=e.appName,a=e.appId,t=e.appVersion,o=arguments.length,i=new Array(o),u=0;u<o;u++)i[u]=arguments[u];var l=i[0],c={};null==(c="string"==typeof l?{screen_name:l}:l).app_name&&null!=n.value&&(c.app_name=n.value),null==c.app_id&&null!=a.value&&(c.app_id=a.value),null==c.app_version&&null!=t.value&&(c.app_version=t.value),s("screen_view",c)},b=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];v.apply(void 0,["set"].concat(n))},A=function(){for(var e=arguments.length,n=new Array(e),a=0;a<e;a++)n[a]=arguments[a];s.apply(void 0,["timing_complete"].concat(n))},j=Object.freeze({__proto__:null,config:p,customMap:f,disable:d,event:s,exception:g,linker:w,pageview:m,purchase:h,query:v,refund:y,screenview:_,set:b,time:A}),k=n.ref(!1),E=n.ref(!1),O=function(){var e=r(),n=e.disableScriptLoader,t=e.preconnectOrigin,o=e.resourceURL,c=e.dataLayerName;if(a()&&u.value&&!E.value)if(E.value=!0,l.value.forEach((function(e){var n=Object.assign({send_page_view:!1},e.params);v("config",e.id,n)})),n.value)k.value=!0;else{var p,f,d="".concat(o.value,"?id=").concat(i.value.id,"&l=").concat(c.value);(p=d,f=t.value,new Promise((function(e,n){var a=document.head||document.getElementsByTagName("head")[0],t=document.createElement("script");if(t.async=!0,t.src=p,t.charset="utf-8",f){var o=document.createElement("link");o.href=f,o.rel="preconnect",a.appendChild(o)}a.appendChild(t),t.onload=e,t.onerror=n}))).then((function(){k.value=!0}))}},N=function(){n.watch((function(){return c.value}),(function(e){return e&&O()}),{immediate:!0})},R=function(){if(a()){var e=r(),n=e.globalObjectName,t=e.dataLayerName;null==window[n.value]&&(window[t.value]=window[t.value]||[],window[n.value]=function(){window[t.value].push(arguments)}),window[n.value]("js",new Date)}},x=n.reactive({template:null,useScreenview:!1,skipSamePath:!0}),L=function(){return n.toRefs(x)},S=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=L(),t=a.template,o=a.useScreenview,r=t.value?t.value(e,n):null;return r||(o.value?{screen_name:e.name}:{page_title:e.name,page_path:e.path,page_location:window.location.href})},P=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=L(),t=a.useScreenview,o=a.skipSamePath;if(!o.value||e.path!==n.path){var r=S(e,n);t.value?_(r):m(r)}},D={install:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(o,n),R(),N(),e.config.globalProperties.$gtag=j}};e.config=p,e.customMap=f,e.default=D,e.disable=d,e.event=s,e.exception=g,e.isReady=k,e.isTracking=c,e.linker=w,e.pageview=m,e.purchase=h,e.query=v,e.refund=y,e.screenview=_,e.set=b,e.time=A,e.trackRouter=function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t(x,a),n.watch((function(){return c.value}),(function(a){a&&e.isReady().then((function(){n.nextTick((function(){P(e.currentRoute.value)})),e.afterEach((function(e,a){n.nextTick((function(){P(e,a)}))}))}))}),{immediate:!0})},e.useGtag=function(){return j},e.useState=r,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=vue-gtag-next.umd.min.js.map