@amplitude/amplitude-js-gtm
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";!function(e,t){var r=e.amplitude||{_q:[],_iq:[]};if(r.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{r.invoked=!0;var n=t.createElement("script");n.type="text/javascript",n.integrity="sha384-QhZkEQJe2NFJ4yDkn/RFnD+NP0FINrep4tUh958v8McXRqszeRUQWbwBCfFqZvnF",n.crossOrigin="anonymous",n.async=!0,n.src="https://cdn.amplitude.com/libs/marketing-analytics-browser-0.2.0-min.js.gz",n.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK");let t=e.amplitude.init;e.amplitude.init=(...r)=>{let n=t(...r);return n.promise.then((()=>e.amplitude.add({name:"gtm-library-enrichment",type:"enrichment",setup:async()=>{},execute:async e=>(e.library="amplitude-ts-gtm/3.0.0",e)}))),n}};var i=t.getElementsByTagName("script")[0];function f(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}}i.parentNode.insertBefore(n,i);for(var s=function(){return this._q=[],this},o=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],a=0;a<o.length;a++)f(s,o[a]);r.Identify=s;for(var u=function(){return this._q=[],this},p=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],d=0;d<p.length;d++)f(u,p[d]);r.Revenue=u;var c=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],l=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];function v(e){function t(t,r){e[t]=function(){var n={promise:new Promise((r=>{e._q.push({name:t,args:Array.prototype.slice.call(arguments,0),resolve:r})}))};if(r)return n}}for(var r=0;r<c.length;r++)t(c[r],!1);for(var n=0;n<l.length;n++)t(l[n],!0)}v(r),r.createInstance=function(){var e=r._iq.push({_q:[]})-1;return v(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document),function(e,t){if(e.amplitude&&"function"==typeof e.amplitude.init){var r=["init","track","identify","setGroup","groupIdentify","revenue","flush","getUserId","setUserId","getSessionId","setSessionId","setDeviceId","getDeviceId","reset","setOptOut","setTransport"],n=["add","append","clearAll","prepend","set","setOnce","remove","preInsert","postInsert"],i=function(t,r){if(t=t.shift(),Array.isArray(t)&&0!==t.length){var i=new e.amplitude.Identify;if(t.forEach((function(e){if(Array.isArray(e)){var t=e.shift();-1!==n.indexOf(t)&&i[t].apply(i,e)}})),!0===r)return i;e.amplitude.identify(i)}},s=function(t){if(!(t.length<3)&&"string"==typeof t[0]&&"string"==typeof t[1]&&Array.isArray(t[2])&&0!==t[2].length){var r=i([t[2]],!0);e.amplitude.groupIdentify(t[0],t[1],r)}},o=function(t){if((t=t.shift()).price&&t.productId){var r=(new e.amplitude.Revenue).setProductId(t.productId).setQuantity(t.quantity||1).setPrice(t.price).setRevenueType(t.revenueType||"").setEventProperties(t.eventProperties||{});e.amplitude.revenue(r)}};e[t]=e[t]||function(){var t=[].slice.call(arguments,0),n=t.shift();if(-1!==r.indexOf(n))return"revenue"===n?o(t):"identify"===n?i(t):"groupIdentify"===n?s(t):e.amplitude[n].apply(this,t)}}}(window,"_amplitude")})(); | ||
(()=>{"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:[]};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{n.invoked=!0;var r=t.createElement("script");r.type="text/javascript",r.integrity="sha384-QhZkEQJe2NFJ4yDkn/RFnD+NP0FINrep4tUh958v8McXRqszeRUQWbwBCfFqZvnF",r.crossOrigin="anonymous",r.async=!0,r.src="https://cdn.amplitude.com/libs/marketing-analytics-browser-0.2.0-min.js.gz",r.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var i=t.getElementsByTagName("script")[0];function f(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}}i.parentNode.insertBefore(r,i);for(var s=function(){return this._q=[],this},o=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],a=0;a<o.length;a++)f(s,o[a]);n.Identify=s;for(var u=function(){return this._q=[],this},p=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],d=0;d<p.length;d++)f(u,p[d]);n.Revenue=u;var c=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],l=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];function v(e){function t(t,n){e[t]=function(){var r={promise:new Promise((n=>{e._q.push({name:t,args:Array.prototype.slice.call(arguments,0),resolve:n})}))};if(n)return r}}for(var n=0;n<c.length;n++)t(c[n],!1);for(var r=0;r<l.length;r++)t(l[r],!0)}v(n),n.createInstance=function(){var e=n._iq.push({_q:[]})-1;return v(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document),function(e,t){if(e.amplitude&&"function"==typeof e.amplitude.init){var n=["init","track","identify","setGroup","groupIdentify","revenue","flush","getUserId","setUserId","getSessionId","setSessionId","setDeviceId","getDeviceId","reset","setOptOut","setTransport"],r=["add","append","clearAll","prepend","set","setOnce","remove","preInsert","postInsert"],i=function(t,n){if(t=t.shift(),Array.isArray(t)&&0!==t.length){var i=new e.amplitude.Identify;if(t.forEach((function(e){if(Array.isArray(e)){var t=e.shift();-1!==r.indexOf(t)&&i[t].apply(i,e)}})),!0===n)return i;e.amplitude.identify(i)}},s=function(t){if(!(t.length<3)&&"string"==typeof t[0]&&"string"==typeof t[1]&&Array.isArray(t[2])&&0!==t[2].length){var n=i([t[2]],!0);e.amplitude.groupIdentify(t[0],t[1],n)}},o=function(t){if((t=t.shift()).price&&t.productId){var n=(new e.amplitude.Revenue).setProductId(t.productId).setQuantity(t.quantity||1).setPrice(t.price).setRevenueType(t.revenueType||"").setEventProperties(t.eventProperties||{});e.amplitude.revenue(n)}},a=function(t){let n=e.amplitude.init(...t);return n.promise.then((()=>e.amplitude.add({name:"gtm-library-enrichment",type:"enrichment",setup:async()=>{},execute:async e=>(e.library="amplitude-ts-gtm/3.0.1",e)}))),n};e[t]=e[t]||function(){var t=[].slice.call(arguments,0),r=t.shift();if(-1!==n.indexOf(r))return"revenue"===r?o(t):"identify"===r?i(t):"groupIdentify"===r?s(t):"init"===r?a(t):e.amplitude[r].apply(this,t)}}}(window,"_amplitude")})(); |
{ | ||
"name": "@amplitude/amplitude-js-gtm", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Amplitude JS SDK Wrapper for use with Google Tag Manager", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -17,21 +17,2 @@ import { version } from '../package.json'; | ||
e.amplitude.runQueuedFunctions || console.log("[Amplitude] Error: could not load SDK") | ||
var gtmLibraryPlugin = () => { | ||
return { | ||
name: 'gtm-library-enrichment', | ||
type: 'enrichment', | ||
setup: async () => undefined, | ||
execute: async (event) => { | ||
event['library'] = `amplitude-ts-gtm/${version}`; | ||
return event; | ||
}, | ||
}; | ||
}; | ||
let _init = e.amplitude.init; // avoid infinite loop | ||
// as plugin order cannot be adjusted, init first then add library plugin to overwrite the library value | ||
e.amplitude.init = (...args) => { | ||
let client = _init(...args); | ||
client.promise.then(() => e.amplitude.add(gtmLibraryPlugin())); | ||
return client; | ||
}; | ||
}; | ||
@@ -216,3 +197,24 @@ var s = t.getElementsByTagName("script")[0]; | ||
var gtmLibraryPlugin = () => { | ||
return { | ||
name: 'gtm-library-enrichment', | ||
type: 'enrichment', | ||
setup: async () => undefined, | ||
execute: async (event) => { | ||
event['library'] = `amplitude-ts-gtm/${version}`; | ||
return event; | ||
}, | ||
}; | ||
}; | ||
var init = function(args) { | ||
// as plugin order cannot be adjusted, init first then add library plugin to overwrite the library value | ||
let client = a.amplitude.init(...args); | ||
client.promise.then( | ||
() => a.amplitude.add(gtmLibraryPlugin()) | ||
); | ||
return client; | ||
}; | ||
// Build the command wrapper logic | ||
@@ -238,2 +240,4 @@ a[p] = a[p] || function() { | ||
if (cmd === 'init') return init(args); | ||
// Otherwise call the method and pass the arguments | ||
@@ -240,0 +244,0 @@ return a.amplitude[cmd].apply(this, args); |
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
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
237
23223