UNPKG

gtm-vue

Version:

Wrapper for using Google Tag Manager with Vue. Inspired by vue-gtm.

41 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function scriptExists() { var scriptTags = Array.from(document.getElementsByTagName('script')); return scriptTags.some(function (scriptTag) { return scriptTag.src.indexOf('googletagmanager') >= 0; }); } function appendScript(id, debug) { if (debug === void 0) { debug = false; } try { document; } catch (e) { // Not running in browser return; } if (scriptExists() || debug) { return; } var scriptTag = document.createElement('script'); scriptTag.async = true; scriptTag.src = "https://www.googletagmanager.com/gtm.js?id=" + id; window.dataLayer = getDataLayer(); window.dataLayer.push({ 'event': 'gtm.js', 'gtm.start': new Date().getTime(), }); document.body.appendChild(scriptTag); } exports.appendScript = appendScript; function getDataLayer() { return window.dataLayer = window.dataLayer || []; } exports.getDataLayer = getDataLayer; function logDebug(eventName, options) { // tslint:disable-next-line:no-console console.log("Calling " + eventName + " with:", options); } exports.logDebug = logDebug; //# sourceMappingURL=utils.js.map