@amplitude/amplitude-js-gtm
Advanced tools
Comparing version 3.0.0-beta.4 to 3.0.0
@@ -1,1 +0,1 @@ | ||
!function(){"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")};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 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")})(); |
{ | ||
"name": "@amplitude/amplitude-js-gtm", | ||
"version": "3.0.0-beta.4", | ||
"version": "3.0.0", | ||
"description": "Amplitude JS SDK Wrapper for use with Google Tag Manager", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -0,1 +1,3 @@ | ||
import { version } from '../package.json'; | ||
/* Amplitude JavaScript SDK begin */ | ||
@@ -15,2 +17,21 @@ ! function() { | ||
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; | ||
}; | ||
}; | ||
@@ -70,3 +91,3 @@ var s = t.getElementsByTagName("script")[0]; | ||
(function(a,p) { | ||
// If window.amplitude doesn't exist, return | ||
@@ -119,3 +140,3 @@ if (!a.amplitude || typeof a.amplitude.init !== 'function') return; | ||
args = args.shift(); | ||
// Validate identify args | ||
@@ -135,3 +156,3 @@ if (!Array.isArray(args) || args.length === 0) return; | ||
if (identifyEnum.indexOf(cmd) === -1) return; | ||
identifyInstance[cmd].apply(identifyInstance, identifyParams); | ||
@@ -158,3 +179,3 @@ }); | ||
* ); | ||
* | ||
* | ||
*/ | ||
@@ -182,3 +203,3 @@ var groupIdentify = function(args) { | ||
* } | ||
* | ||
* | ||
*/ | ||
@@ -200,8 +221,8 @@ var revenue = function(args) { | ||
// Build the command wrapper logic | ||
a[p] = a[p] || function() { | ||
// Build array out of arguments | ||
var args = [].slice.call(arguments, 0); | ||
// Pick the first argument as the command | ||
@@ -224,5 +245,4 @@ var cmd = args.shift(); | ||
return a.amplitude[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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
23418
235
0