UNPKG

swup

Version:

Animated page transitions with css.

25 lines (21 loc) 1.02 kB
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; module.exports = { name: 'swupGtmPlugin', options: { runScripts: false }, exec: function exec(options, swup) { document.addEventListener('swup:contentReplaced', function (event) { if (_typeof(window.dataLayer) === 'object') { var object = { 'event': 'VirtualPageview', 'virtualPageURL': window.location.pathname + window.location.search, 'virtualPageTitle': document.title }; window.dataLayer.push(object); swup.log('GTM pageview (url \'' + object.virtualPageURL + '\').'); } else { console.warn('GTM is not loaded.'); } }); } };