@amplitude/amplitude-js-gtm
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -1,1 +0,1 @@ | ||
(()=>{"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")})(); | ||
(()=>{"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{var n=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},i=function(e,t,r){return function(n){e._q.push({name:t,args:Array.prototype.slice.call(r,0),resolve:n})}},s=function(e,t,r){e[t]=function(){if(r)return{promise:new Promise(i(e,t,Array.prototype.slice.call(arguments)))}}},o=function(e){for(var t=0;t<v.length;t++)s(e,v[t],!1);for(var r=0;r<m.length;r++)s(e,m[r],!0)};r.invoked=!0;var a=t.createElement("script");a.type="text/javascript",a.integrity="sha384-D3GO8BuPsJOXpw91yAMykYKOR35cmmZ15qHBaEcl5aU3po1Xnyw2m+J4lL2+Cs1t",a.crossOrigin="anonymous",a.async=!0,a.src="https://cdn.amplitude.com/libs/marketing-analytics-browser-0.4.0-min.js.gz",a.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var u=t.getElementsByTagName("script")[0];u.parentNode.insertBefore(a,u);for(var p=function(){return this._q=[],this},c=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],d=0;d<c.length;d++)n(p,c[d]);r.Identify=p;for(var l=function(){return this._q=[],this},f=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],y=0;y<f.length;y++)n(l,f[y]);r.Revenue=l;var v=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],m=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];o(r),r.createInstance=function(e){return r._iq[e]={_q:[]},o(r._iq[e]),r._iq[e]},e.amplitude=r}}(window,document),function(e,t){var r={};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"],i=["add","append","clearAll","prepend","set","setOnce","remove","preInsert","postInsert"],s=function(t,r,n){if(r=r.shift(),Array.isArray(r)&&0!==r.length){var s=new e.amplitude.Identify;if(r.forEach((function(e){if(Array.isArray(e)){var t=e.shift();-1!==i.indexOf(t)&&s[t].apply(s,e)}})),!0===n)return s;t.identify(s)}},o=function(e,t){if(!(t.length<3)&&"string"==typeof t[0]&&"string"==typeof t[1]&&Array.isArray(t[2])&&0!==t[2].length){var r=s(e,[t[2]],!0);e.groupIdentify(t[0],t[1],r)}},a=function(t,r){if((r=r.shift()).price&&r.productId){var n=(new e.amplitude.Revenue).setProductId(r.productId).setQuantity(r.quantity||1).setPrice(r.price).setRevenueType(r.revenueType||"").setEventProperties(r.eventProperties||{});t.revenue(n)}},u=function(e,t){let r=e.init(...t).promise;return r.then((()=>e.add({name:"gtm-library-enrichment",type:"enrichment",setup:async()=>{},execute:async e=>(e.library="amplitude-ts-gtm/3.1.0",e)}))),r};e[t]=e[t]||function(){var t=[].slice.call(arguments,0),i=t.shift();r[i]||(r[i]=e.amplitude.createInstance(i));var p=r[i],c=t.shift();if(-1!==n.indexOf(c))return"revenue"===c?a(p,t):"identify"===c?s(p,t):"groupIdentify"===c?o(p,t):"init"===c?u(p,t):p[c].apply(this,t)}}}(window,"_amplitude")})(); |
{ | ||
"name": "@amplitude/amplitude-js-gtm", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Amplitude JS SDK Wrapper for use with Google Tag Manager", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import { version } from '../package.json'; | ||
/* Amplitude JavaScript SDK begin */ | ||
! function() { | ||
"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 s = t.getElementsByTagName("script")[0]; | ||
function v(e, t) { | ||
e.prototype[t] = function() { | ||
return this._q.push({ | ||
name: t, | ||
args: Array.prototype.slice.call(arguments, 0) | ||
}), this | ||
} | ||
} | ||
s.parentNode.insertBefore(r, s); | ||
for (var o = function() { | ||
return this._q = [], this | ||
}, i = ["add", "append", "clearAll", "prepend", "set", "setOnce", "unset", "preInsert", "postInsert", "remove", "getUserProperties"], a = 0; a < i.length; a++) v(o, i[a]); | ||
n.Identify = o; | ||
for (var u = function() { | ||
return this._q = [], this | ||
}, c = ["getEventProperties", "setProductId", "setQuantity", "setPrice", "setRevenue", "setRevenueType", "setEventProperties"], p = 0; p < c.length; p++) v(u, c[p]); | ||
n.Revenue = u; | ||
var l = ["getDeviceId", "setDeviceId", "getSessionId", "setSessionId", "getUserId", "setUserId", "setOptOut", "setTransport", "reset"], | ||
d = ["init", "add", "remove", "track", "logEvent", "identify", "groupIdentify", "setGroup", "revenue", "flush"]; | ||
function f(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 < l.length; n++) t(l[n], !1); | ||
for (var r = 0; r < d.length; r++) t(d[r], !0) | ||
} | ||
f(n), n.createInstance = function() { | ||
var e = n._iq.push({ | ||
_q: [] | ||
}) - 1; | ||
return f(n._iq[e]), n._iq[e] | ||
}, e.amplitude = n | ||
} | ||
}(window, document) | ||
}(); | ||
!function(){"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{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))}}},i=function(e){for(var t=0;t<m.length;t++)o(e,m[t],!1);for(var n=0;n<y.length;n++)o(e,y[n],!0)};n.invoked=!0;var a=t.createElement("script");a.type="text/javascript",a.integrity="sha384-D3GO8BuPsJOXpw91yAMykYKOR35cmmZ15qHBaEcl5aU3po1Xnyw2m+J4lL2+Cs1t",a.crossOrigin="anonymous",a.async=!0,a.src="https://cdn.amplitude.com/libs/marketing-analytics-browser-0.4.0-min.js.gz",a.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var c=t.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c);for(var u=function(){return this._q=[],this},l=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],p=0;p<l.length;p++)r(u,l[p]);n.Identify=u;for(var d=function(){return this._q=[],this},f=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],v=0;v<f.length;v++)r(d,f[v]);n.Revenue=d;var m=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],y=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];i(n),n.createInstance=function(e){return n._iq[e]={_q:[]},i(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}(); | ||
/* Amplitude JavaScript SDK end */ | ||
@@ -71,2 +9,3 @@ | ||
(function(a,p) { | ||
var instances = {}; | ||
@@ -118,3 +57,3 @@ // If window.amplitude doesn't exist, return | ||
*/ | ||
var identify = function(args, group) { | ||
var identify = function(client, args, group) { | ||
args = args.shift(); | ||
@@ -143,3 +82,3 @@ | ||
a.amplitude.identify(identifyInstance); | ||
client.identify(identifyInstance); | ||
}; | ||
@@ -161,3 +100,3 @@ | ||
*/ | ||
var groupIdentify = function(args) { | ||
var groupIdentify = function(client, args) { | ||
// Validate the arguments | ||
@@ -169,5 +108,5 @@ if (args.length < 3) return; | ||
// Get the Identify instance object | ||
var groupIdentifyInstance = identify([args[2]], true); | ||
var groupIdentifyInstance = identify(client, [args[2]], true); | ||
a.amplitude.groupIdentify(args[0], args[1], groupIdentifyInstance); | ||
client.groupIdentify(args[0], args[1], groupIdentifyInstance); | ||
}; | ||
@@ -186,3 +125,3 @@ | ||
*/ | ||
var revenue = function(args) { | ||
var revenue = function(client, args) { | ||
args = args.shift(); | ||
@@ -199,3 +138,3 @@ // Validate revenue args | ||
a.amplitude.revenue(revenue); | ||
client.revenue(revenue); | ||
}; | ||
@@ -215,9 +154,9 @@ | ||
var init = function(args) { | ||
var init = function(client, 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()) | ||
let promise = client.init(...args).promise; | ||
promise.then( | ||
() => client.add(gtmLibraryPlugin()) | ||
); | ||
return client; | ||
return promise; | ||
}; | ||
@@ -231,2 +170,9 @@ | ||
// Pick the first argument as the instance name | ||
var name = args.shift(); | ||
if (!instances[name]) { | ||
instances[name] = a.amplitude.createInstance(name); | ||
} | ||
var client = instances[name]; | ||
// Pick the first argument as the command | ||
@@ -239,16 +185,16 @@ var cmd = args.shift(); | ||
// Handle Revenue separately | ||
if (cmd === 'revenue') return revenue(args); | ||
if (cmd === 'revenue') return revenue(client, args); | ||
// Handle Identify separately | ||
if (cmd === 'identify') return identify(args); | ||
if (cmd === 'identify') return identify(client, args); | ||
// Handle GroupIdentify separately | ||
if (cmd === 'groupIdentify') return groupIdentify(args); | ||
if (cmd === 'groupIdentify') return groupIdentify(client, args); | ||
if (cmd === 'init') return init(args); | ||
if (cmd === 'init') return init(client, args); | ||
// Otherwise call the method and pass the arguments | ||
return a.amplitude[cmd].apply(this, args); | ||
return client[cmd].apply(this, args); | ||
}; | ||
})(window, '_amplitude') | ||
/* Amplitude wrapper end */ |
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
22567
191