UNPKG

react-ga-gtm

Version:
1 lines 15.6 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"),require("prop-types"));else if("function"==typeof define&&define.amd)define(["react","prop-types"],t);else{var n="object"==typeof exports?t(require("react"),require("prop-types")):t(e.react,e["prop-types"]);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}("undefined"!=typeof self?self:this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t,n){"use strict";function r(e){console.warn("[react-ga]",e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r},function(t,n){t.exports=e},function(e,n){e.exports=t},function(e,t,n){"use strict";function r(e){return e.replace(/^\s+|\s+$/g,"")}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function a(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function o(e){return(0,_.default)(e,K)}function u(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var a=n[0];if("function"==typeof U){if("string"!=typeof a)return void(0,L.default)("ga command must be a string");!Z&&Array.isArray(e)||U.apply(void 0,n),Array.isArray(e)&&e.forEach(function(e){U.apply(void 0,i([e+"."+a].concat(n.slice(1))))})}}function l(e,t){return e?t&&"object"===(void 0===t?"undefined":O(t))&&t.gtmTrackingId?void(0,L.default)("GTM initializes the GA"):(t&&(t.debug&&!0===t.debug&&(F=!0),!1===t.titleCase&&(K=!1)),void(t&&t.gaOptions?U("create",e,t.gaOptions):U("create",e,"auto"))):void(0,L.default)("gaTrackingID is required in initialize()")}function f(e){if("string"==typeof e)return e;if(Array.isArray(e)&&e.length){var t=e.find(function(e){return e.trackingId});if(t&&"object"!==(void 0===t?"undefined":O(t)))return t.trackingId}return null}function c(e,t){if(t&&!0===t.testMode)V=!0;else{if("undefined"==typeof window)return!1;var n=f(e);t&&"object"===(void 0===t?"undefined":O(t))&&t.gtmTrackingId?(0,E.default)(n,t):(0,x.default)(t)}return Z=!t||"boolean"!=typeof t.alwaysSendToDefaultTracker||t.alwaysSendToDefaultTracker,Array.isArray(e)?e.forEach(function(e){if("object"!==(void 0===e?"undefined":O(e)))return void(0,L.default)("All configs must be an object");l(e.trackingId,e)}):l(e,t),!0}function d(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.length>0&&(U.apply(void 0,t),F&&((0,N.default)("called ga('arguments');"),(0,N.default)("with arguments: "+JSON.stringify(t)))),window.ga}function s(e,t){return e?"object"!==(void 0===e?"undefined":O(e))?void(0,L.default)("Expected `fieldsObject` arg to be an Object"):(0===Object.keys(e).length&&(0,L.default)("empty `fieldsObject` given to .set()"),u(t,"set",e),void(F&&((0,N.default)("called ga('set', fieldsObject);"),(0,N.default)("with fieldsObject: "+JSON.stringify(e))))):void(0,L.default)("`fieldsObject` is required in .set()")}function g(e,t){u(t,"send",e),F&&((0,N.default)("called ga('send', fieldObject);"),(0,N.default)("with fieldObject: "+JSON.stringify(e)),(0,N.default)("with trackers: "+JSON.stringify(t)))}function p(e,t,n){if(!e)return void(0,L.default)("path is required in .pageview()");var r=(0,M.default)(e);if(""===r)return void(0,L.default)("path cannot be an empty string in .pageview()");var a={};if(n&&(a.title=n),"function"==typeof d&&(u(t,"send",w({hitType:"pageview",page:r},a)),F)){(0,N.default)("called ga('send', 'pageview', path);");var i="";n&&(i=" and title: "+n),(0,N.default)("with path: "+r+i)}}function y(e,t){if(!e)return void(0,L.default)("modalName is required in .modalview(modalName)");var n=(0,T.default)((0,M.default)(e));if(""===n)return void(0,L.default)("modalName cannot be an empty string or a single / in .modalview()");if("function"==typeof d){var r="/modal/"+n;u(t,"send","pageview",r),F&&((0,N.default)("called ga('send', 'pageview', path);"),(0,N.default)("with path: "+r))}}function v(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.category,n=e.variable,r=e.value,a=e.label,i=arguments[1];if("function"==typeof d){if(!t||!n||!r||"number"!=typeof r)return void(0,L.default)("args.category, args.variable AND args.value are required in timing() AND args.value has to be a number");var u={hitType:"timing",timingCategory:o(t),timingVar:o(n),timingValue:r};a&&(u.timingLabel=o(a)),g(u,i)}}function b(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],n=e.category,r=e.action,i=e.label,u=e.value,l=e.nonInteraction,f=e.transport,c=a(e,["category","action","label","value","nonInteraction","transport"]);if("function"==typeof d){if(!n||!r)return void(0,L.default)("args.category AND args.action are required in event()");var s={hitType:"event",eventCategory:o(n),eventAction:o(r)};i&&(s.eventLabel=o(i)),void 0!==u&&("number"!=typeof u?(0,L.default)("Expected `args.value` arg to be a Number."):s.eventValue=u),void 0!==l&&("boolean"!=typeof l?(0,L.default)("`args.nonInteraction` must be a boolean."):s.nonInteraction=l),void 0!==f&&("string"!=typeof f?(0,L.default)("`args.transport` must be a string."):(-1===["beacon","xhr","image"].indexOf(f)&&(0,L.default)("`args.transport` must be either one of these values: `beacon`, `xhr` or `image`"),s.transport=f)),Object.keys(c).filter(function(e){return"dimension"===e.substr(0,"dimension".length)}).forEach(function(e){s[e]=c[e]}),Object.keys(c).filter(function(e){return"metric"===e.substr(0,"metric".length)}).forEach(function(e){s[e]=c[e]}),g(s,t)}}function m(e,t){var n=e.description,r=e.fatal;if("function"==typeof d){var a={hitType:"exception"};n&&(a.exDescription=o(n)),void 0!==r&&("boolean"!=typeof r?(0,L.default)("`args.fatal` must be a boolean."):a.exFatal=r),g(a,t)}}function h(e,t,n){if("function"!=typeof t)return void(0,L.default)("hitCallback function is required");if("function"==typeof d){if(!e||!e.label)return void(0,L.default)("args.label is required in outboundLink()");var r={hitType:"event",eventCategory:"Outbound",eventAction:"Click",eventLabel:o(e.label)},a=!1,i=function(){a=!0,t()},u=setTimeout(i,250),l=function(){clearTimeout(u),a||t()};r.hitCallback=l,g(r,n)}else setTimeout(t,0)}Object.defineProperty(t,"__esModule",{value:!0}),t.GoogleTagManagerScript=t.GoogleTagManagerIframe=t.testModeAPI=t.OutboundLink=t.plugin=void 0;var w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},O="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};t.initialize=c,t.ga=d,t.set=s,t.send=g,t.pageview=p,t.modalview=y,t.timing=v,t.event=b,t.exception=m,t.outboundLink=h;var j=n(5),_=r(j),k=n(8),T=r(k),A=n(3),M=r(A),P=n(9),x=r(P),q=n(10),E=r(q),I=n(0),L=r(I),S=n(11),N=r(S),C=n(12),D=r(C),G=n(13),H=r(G),J=n(14),B=r(J),z=n(15),R=r(z),F=!1,K=!0,V=!1,Z=!0,$=[],U=function(){for(var e,t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];return V?D.default.ga.apply(D.default,n):window.ga?($.length&&($.map(function(e){var t;return(t=window).ga.apply(t,i(e))}),$=[]),(e=window).ga.apply(e,n)):($.push(n),null)},Q=t.plugin={require:function(e,t){if("function"==typeof d){if(!e)return void(0,L.default)("`name` is required in .require()");var n=(0,M.default)(e);if(""===n)return void(0,L.default)("`name` cannot be an empty string in .require()");if(t){if("object"!==(void 0===t?"undefined":O(t)))return void(0,L.default)("Expected `options` arg to be an Object");0===Object.keys(t).length&&(0,L.default)("Empty `options` given to .require()"),d("require",n,t),F&&(0,N.default)("called ga('require', '"+n+"', "+JSON.stringify(t))}else d("require",n),F&&(0,N.default)("called ga('require', '"+n+"');")}},execute:function(e,t){var n=void 0,r=void 0;if(1==(arguments.length<=2?0:arguments.length-2)?n=arguments.length<=2?void 0:arguments[2]:(r=arguments.length<=2?void 0:arguments[2],n=arguments.length<=3?void 0:arguments[3]),"function"==typeof d)if("string"!=typeof e)(0,L.default)("Expected `pluginName` arg to be a String.");else if("string"!=typeof t)(0,L.default)("Expected `action` arg to be a String.");else{var a=e+":"+t;n=n||null,r&&n?(d(a,r,n),F&&((0,N.default)("called ga('"+a+"');"),(0,N.default)('actionType: "'+r+'" with payload: '+JSON.stringify(n)))):n?(d(a,n),F&&((0,N.default)("called ga('"+a+"');"),(0,N.default)("with payload: "+JSON.stringify(n)))):(d(a),F&&(0,N.default)("called ga('"+a+"');"))}}};H.default.origTrackLink=H.default.trackLink,H.default.trackLink=h;var W=t.OutboundLink=H.default,X=(t.testModeAPI=D.default,t.GoogleTagManagerIframe=B.default),Y=t.GoogleTagManagerScript=R.default;t.default={initialize:c,ga:d,set:s,send:g,pageview:p,modalview:y,timing:v,event:b,exception:m,plugin:Q,outboundLink:h,OutboundLink:W,GoogleTagManagerIframe:X,GoogleTagManagerScript:Y,testModeAPI:D.default}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function a(e,t){return(0,o.default)(e)?((0,c.default)("This arg looks like an email address, redacting."),d):t?(0,l.default)(e):e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=a;var i=n(6),o=r(i),u=n(7),l=r(u),f=n(0),c=r(f),d="REDACTED (Potential Email Address)"},function(e,t,n){"use strict";function r(e){return/[^@]+@[^@]+/.test(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r},function(e,t,n){"use strict";function r(e){return(0,i.default)(e).replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g,function(e,t,n){return t>0&&t+e.length!==n.length&&e.search(o)>-1&&":"!==n.charAt(t-2)&&("-"!==n.charAt(t+e.length)||"-"===n.charAt(t-1))&&n.charAt(t-1).search(/[^\s-]/)<0?e.toLowerCase():e.substr(1).search(/[A-Z]|\../)>-1?e:e.charAt(0).toUpperCase()+e.substr(1)})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r;var a=n(3),i=function(e){return e&&e.__esModule?e:{default:e}}(a),o=/^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i},function(e,t,n){"use strict";function r(e){return"/"===e.substring(0,1)?e.substring(1):e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){!function(e,t,n,r,a,i,o){e.GoogleAnalyticsObject=a,e[a]=e[a]||function(){(e[a].q=e[a].q||[]).push(arguments)},e[a].l=1*new Date,i=t.createElement(n),o=t.getElementsByTagName(n)[0],i.async=1,i.src=r,o.parentNode.insertBefore(i,o)}(window,document,"script",e&&e.gaAddress?e.gaAddress:"https://www.google-analytics.com/analytics.js","ga")}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){!function(e,t,n,r,a,i,o,u){e[r]=e[r]||[],e[u]=function(){e[r].push(arguments)},e[u]({"gtm.start":(new Date).getTime(),event:"gtm.js"}),e[u]("config",i);var l=t.getElementsByTagName(n)[0],f=t.createElement(n);f.async=!0,f.src=o+"?id="+a,l.parentNode.insertBefore(f,l)}(window,document,"script","dataLayer",t&&t.gtmTrackingId,e,t&&t.gtmAddress?t.gtmAddress:"https://www.googletagmanager.com/gtm.js","gtag")}},function(e,t,n){"use strict";function r(e){console.info("[react-ga]",e)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=r},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=t.gaCalls=[];t.default={calls:r,ga:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];r.push([].concat(t))}}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=n(1),c=r(f),d=n(2),s=r(d),g=n(0),p=r(g),y="_blank",v=1,b=function(e){function t(){var e,n,r,o;a(this,t);for(var u=arguments.length,l=Array(u),f=0;f<u;f++)l[f]=arguments[f];return n=r=i(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(l))),r.handleClick=function(e){var n=r.props,a=n.target,i=n.eventLabel,o=n.to,u=n.onClick,l={label:i},f=a!==y,c=!(e.ctrlKey||e.shiftKey||e.metaKey||e.button===v);f&&c?(e.preventDefault(),t.trackLink(l,function(){window.location.href=o})):t.trackLink(l,function(){}),u&&u(e)},o=n,i(r,o)}return o(t,e),l(t,[{key:"render",value:function(){var e=u({},this.props,{href:this.props.to,onClick:this.handleClick});return delete e.eventLabel,c.default.createElement("a",e)}}]),t}(f.Component);b.propTypes={eventLabel:s.default.string.isRequired,target:s.default.string,to:s.default.string,onClick:s.default.func},b.defaultProps={target:null,to:null,onClick:null},b.trackLink=function(){(0,p.default)("ga tracking not enabled")},t.default=b},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function a(e){return o.default.createElement("noscript",null,o.default.createElement("iframe",{title:"googleTagManagerIframe",src:"https://"+e.gtmHost+"/ns.html?id="+e.gtmTrackingId,height:"0",width:"0",style:{display:"none",visibility:"hidden"}}))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=a;var i=n(1),o=r(i),u=n(2),l=r(u);a.propTypes={gtmHost:l.default.string,gtmTrackingId:l.default.string.isRequired},a.defaultProps={gtmHost:"www.googletagmanager.com"}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function a(e){return o.default.createElement("script",{dangerouslySetInnerHTML:{__html:f(e.gtmHost,e.gtmTrackingId)}})}Object.defineProperty(t,"__esModule",{value:!0}),t.getGoogleTagManagerScript=void 0,t.default=a;var i=n(1),o=r(i),u=n(2),l=r(u),f=t.getGoogleTagManagerScript=function(e,t){return"(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\nnew Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\nj=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n'https://"+e+"/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n})(window,document,'script','dataLayer','"+t+"');"};a.propTypes={gtmHost:l.default.string,gtmTrackingId:l.default.string.isRequired},a.defaultProps={gtmHost:"www.googletagmanager.com"}}])});