Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@amplitude/amplitude-js-gtm

Package Overview
Dependencies
Maintainers
16
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplitude/amplitude-js-gtm - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

.eslintrc.json

2

dist/index.js

@@ -1,1 +0,1 @@

!function(e,t){var n=e.amplitude||{_q:[],_iq:{}},i=t.createElement("script");i.type="text/javascript",i.integrity="sha384-tzcaaCH5+KXD4sGaDozev6oElQhsVfbJvdi3//c2YvbY02LrNlbpGdt3Wq4rWonS",i.crossOrigin="anonymous",i.async=!0,i.src="https://cdn.amplitude.com/libs/amplitude-8.5.0-min.gz.js",i.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var r=t.getElementsByTagName("script")[0];function s(e,t){e.prototype[t]=function(){return this._q.push([t].concat(Array.prototype.slice.call(arguments,0))),this}}r.parentNode.insertBefore(i,r);for(var o=function(){return this._q=[],this},a=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove"],p=0;p<a.length;p++)s(o,a[p]);n.Identify=o;for(var u=function(){return this._q=[],this},c=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"],l=0;l<c.length;l++)s(u,c[l]);n.Revenue=u;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","enableTracking","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","onInit","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"];function v(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}for(var n=0;n<d.length;n++)t(d[n])}v(n),n.getInstance=function(e){return e=(e&&0!==e.length?e:"$default_instance").toLowerCase(),Object.prototype.hasOwnProperty.call(n._iq,e)||(n._iq[e]={_q:[]},v(n._iq[e])),n._iq[e]},e.amplitude=n}(window,document),function(e,t){if(e.amplitude&&"function"==typeof e.amplitude.getInstance){var n=["init","setOptOut","isNewSession","getSessionId","setSessionId","setUserId","setUserProperties","clearUserProperties","setGroup","regenerateDeviceId","setDeviceId","setVersionName","logEvent","logEventWithTimestamp","logEventWithGroups","revenue","identify"],i=["add","append","prepend","set","setOnce","unset","preInsert"],r=function(t,n){var r=new e.amplitude.Identify;Array.isArray(n)&&0!==n.length&&(n[0].forEach((function(e){var t=e.shift();-1!==i.indexOf(t)&&r[t].apply(r,e)})),t.identify(r))},s=function(t,n){if((n=n.shift()).price&&n.id){var i=(new e.amplitude.Revenue).setProductId(n.id).setQuantity(n.quantity||1).setPrice(n.price).setRevenueType(n.revenueType||"").setEventProperties(n.eventProperties||{});t.logRevenueV2(i)}};e[t]=e[t]||function(){var t=[].slice.call(arguments,0),i=t.shift(),o=null,a=i.match(/^(.+)\.(.+)$/);if(a&&3===a.length&&(o=a[1],i=a[2]),-1!==n.indexOf(i)){var p=e.amplitude.getInstance(o);return"revenue"===i?s(p,t):"identify"===i?r(p,t):p[i].apply(p,t)}}}}(window,"_amplitude");
(()=>{"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}},i=t.createElement("script");i.type="text/javascript",i.integrity="sha384-4rr7CTymHc64YjTTL6O3ktfsHYI1yJnQdmKv4zFoe+frjXb05MfzzuLLIAgJ/XHs",i.crossOrigin="anonymous",i.async=!0,i.src="https://cdn.amplitude.com/libs/amplitude-8.11.0-min.gz.js",i.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var r=t.getElementsByTagName("script")[0];function s(e,t){e.prototype[t]=function(){return this._q.push([t].concat(Array.prototype.slice.call(arguments,0))),this}}r.parentNode.insertBefore(i,r);for(var o=function(){return this._q=[],this},a=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove"],u=0;u<a.length;u++)s(o,a[u]);n.Identify=o;for(var p=function(){return this._q=[],this},c=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"],l=0;l<c.length;l++)s(p,c[l]);n.Revenue=p;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","enableTracking","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","onInit","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId","setLibrary"];function f(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}for(var n=0;n<d.length;n++)t(d[n])}f(n),n.getInstance=function(e){return e=(e&&0!==e.length?e:"$default_instance").toLowerCase(),Object.prototype.hasOwnProperty.call(n._iq,e)||(n._iq[e]={_q:[]},f(n._iq[e])),n._iq[e]},e.amplitude=n}(window,document),function(e,t){if(e.amplitude&&"function"==typeof e.amplitude.getInstance){e.amplitude.getInstance().setLibrary("amplitude-js-gtm","2.0.0");var n=["init","setOptOut","isNewSession","getSessionId","setSessionId","setUserId","setUserProperties","clearUserProperties","setGroup","regenerateDeviceId","setDeviceId","setVersionName","logEvent","logEventWithTimestamp","logEventWithGroups","revenue","identify"],i=["add","append","prepend","set","setOnce","unset","preInsert"],r=function(t,n){var r=new e.amplitude.Identify;Array.isArray(n)&&0!==n.length&&(n[0].forEach((function(e){var t=e.shift();-1!==i.indexOf(t)&&r[t].apply(r,e)})),t.identify(r))},s=function(t,n){if((n=n.shift()).price&&n.id){var i=(new e.amplitude.Revenue).setProductId(n.id).setQuantity(n.quantity||1).setPrice(n.price).setRevenueType(n.revenueType||"").setEventProperties(n.eventProperties||{});t.logRevenueV2(i)}};e[t]=e[t]||function(){var t=[].slice.call(arguments,0),i=t.shift(),o=null,a=i.match(/^(.+)\.(.+)$/);if(a&&3===a.length&&(o=a[1],i=a[2]),-1!==n.indexOf(i)){var u=e.amplitude.getInstance(o);return"revenue"===i?s(u,t):"identify"===i?r(u,t):u[i].apply(u,t)}}}}(window,"_amplitude")})();
{
"name": "@amplitude/amplitude-js-gtm",
"version": "1.0.1",
"version": "2.0.0",
"description": "Amplitude JS SDK Wrapper for use with Google Tag Manager",
"main": "dist/index.js",
"scripts": {
"build:prod": "webpack --mode production",
"build:prod": "webpack --mode production",
"lint": "yarn run lint:eslint && yarn run lint:prettier",
"lint:eslint": "eslint src/",
"lint:fix": "eslint --fix src/ && yarn prettier --write src",
"lint:prettier": "prettier --check src",
"prepare": "yarn build:prod"

@@ -21,2 +25,7 @@ },

"devDependencies": {
"@amplitude/eslint-plugin-amplitude": "^1.0.1",
"eslint": "^8.2.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.4.1",
"webpack": "^5.60.0",

@@ -23,0 +32,0 @@ "webpack-cli": "^4.9.1"

@@ -0,155 +1,212 @@

import { version } from '../package.json';
/* Amplitude JavaScript SDK begin */
(function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement("script")
;r.type="text/javascript"
;r.integrity="sha384-tzcaaCH5+KXD4sGaDozev6oElQhsVfbJvdi3//c2YvbY02LrNlbpGdt3Wq4rWonS"
;r.crossOrigin="anonymous";r.async=true
;r.src="https://cdn.amplitude.com/libs/amplitude-8.5.0-min.gz.js"
;r.onload=function(){if(!e.amplitude.runQueuedFunctions){
console.log("[Amplitude] Error: could not load SDK")}}
;var i=t.getElementsByTagName("script")[0];i.parentNode.insertBefore(r,i)
;function s(e,t){e.prototype[t]=function(){
this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));return this}}
var o=function(){this._q=[];return this}
;var a=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove"]
;for(var c=0;c<a.length;c++){s(o,a[c])}n.Identify=o;var u=function(){this._q=[]
;return this}
;var l=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]
;for(var p=0;p<l.length;p++){s(u,l[p])}n.Revenue=u
;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","enableTracking","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","onInit","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
;function v(e){function t(t){e[t]=function(){
e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}
for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){
e=(!e||e.length===0?"$default_instance":e).toLowerCase()
;if(!Object.prototype.hasOwnProperty.call(n._iq,e)){n._iq[e]={_q:[]};v(n._iq[e])
}return n._iq[e]};e.amplitude=n})(window,document);
(function (e, t) {
var n = e.amplitude || { _q: [], _iq: {} };
var r = t.createElement('script');
r.type = 'text/javascript';
r.integrity = 'sha384-4rr7CTymHc64YjTTL6O3ktfsHYI1yJnQdmKv4zFoe+frjXb05MfzzuLLIAgJ/XHs';
r.crossOrigin = 'anonymous';
r.async = true;
r.src = 'https://cdn.amplitude.com/libs/amplitude-8.11.0-min.gz.js';
r.onload = function () {
if (!e.amplitude.runQueuedFunctions) {
console.log('[Amplitude] Error: could not load SDK');
}
};
var s = t.getElementsByTagName('script')[0];
s.parentNode.insertBefore(r, s);
function i(e, t) {
e.prototype[t] = function () {
this._q.push([t].concat(Array.prototype.slice.call(arguments, 0)));
return this;
};
}
var o = function () {
this._q = [];
return this;
};
var a = ['add', 'append', 'clearAll', 'prepend', 'set', 'setOnce', 'unset', 'preInsert', 'postInsert', 'remove'];
for (var c = 0; c < a.length; c++) {
i(o, a[c]);
}
n.Identify = o;
var u = function () {
this._q = [];
return this;
};
var l = ['setProductId', 'setQuantity', 'setPrice', 'setRevenueType', 'setEventProperties'];
for (var p = 0; p < l.length; p++) {
i(u, l[p]);
}
n.Revenue = u;
var d = [
'init',
'logEvent',
'logRevenue',
'setUserId',
'setUserProperties',
'setOptOut',
'setVersionName',
'setDomain',
'setDeviceId',
'enableTracking',
'setGlobalUserProperties',
'identify',
'clearUserProperties',
'setGroup',
'logRevenueV2',
'regenerateDeviceId',
'groupIdentify',
'onInit',
'logEventWithTimestamp',
'logEventWithGroups',
'setSessionId',
'resetSessionId',
'setLibrary',
];
function v(e) {
function t(t) {
e[t] = function () {
e._q.push([t].concat(Array.prototype.slice.call(arguments, 0)));
};
}
for (var n = 0; n < d.length; n++) {
t(d[n]);
}
}
v(n);
n.getInstance = function (e) {
e = (!e || e.length === 0 ? '$default_instance' : e).toLowerCase();
if (!Object.prototype.hasOwnProperty.call(n._iq, e)) {
n._iq[e] = { _q: [] };
v(n._iq[e]);
}
return n._iq[e];
};
e.amplitude = n;
})(window, document);
/* Amplitude JavaScript SDK end */
/* Amplitude Wrapper begin */
(function(a,p) {
// If window.amplitude doesn't exist, return
if (!a.amplitude || typeof a.amplitude.getInstance !== 'function') return;
(function (a, p) {
// If window.amplitude doesn't exist, return
if (!a.amplitude || typeof a.amplitude.getInstance !== 'function') return;
// Enumerate available events
var eventEnum = [
'init',
'setOptOut',
'isNewSession',
'getSessionId',
'setSessionId',
'setUserId',
'setUserProperties',
'clearUserProperties',
'setGroup',
'regenerateDeviceId',
'setDeviceId',
'setVersionName',
'logEvent',
'logEventWithTimestamp',
'logEventWithGroups',
'revenue',
'identify'
];
a.amplitude.getInstance().setLibrary('amplitude-js-gtm', version);
var identifyEnum = [
'add',
'append',
'prepend',
'set',
'setOnce',
'unset',
'preInsert'
];
// Enumerate available events
var eventEnum = [
'init',
'setOptOut',
'isNewSession',
'getSessionId',
'setSessionId',
'setUserId',
'setUserProperties',
'clearUserProperties',
'setGroup',
'regenerateDeviceId',
'setDeviceId',
'setVersionName',
'logEvent',
'logEventWithTimestamp',
'logEventWithGroups',
'revenue',
'identify',
];
/* To work with the identify API, pass an array of identify operation (each an array in itself)
* with the command and parameters included.
*
* window._amplitude('<instanceName.>identify', [
* ['add', 'someUserProp', 1],
* ['add', 'someOtherUserProp', 2],
* ['prepend', 'anotherUserProp', 'someValue']
* ]);
*
*/
var identify = function(amplitudeInstance, args) {
var identifyInstance = new a.amplitude.Identify();
// Validate identify args
if (!Array.isArray(args) || args.length === 0) return;
var identifyEnum = ['add', 'append', 'prepend', 'set', 'setOnce', 'unset', 'preInsert'];
// Loop through the commands array and execute each
args[0].forEach(function(identifyParams) {
var cmd = identifyParams.shift();
/* To work with the identify API, pass an array of identify operation (each an array in itself)
* with the command and parameters included.
*
* window._amplitude('<instanceName.>identify', [
* ['add', 'someUserProp', 1],
* ['add', 'someOtherUserProp', 2],
* ['prepend', 'anotherUserProp', 'someValue']
* ]);
*
*/
var identify = function (amplitudeInstance, args) {
var identifyInstance = new a.amplitude.Identify();
// If not a valid "identify" command, return
if (identifyEnum.indexOf(cmd) === -1) return;
identifyInstance[cmd].apply(identifyInstance, identifyParams);
});
// Validate identify args
if (!Array.isArray(args) || args.length === 0) return;
amplitudeInstance.identify(identifyInstance);
};
// Loop through the commands array and execute each
args[0].forEach(function (identifyParams) {
var cmd = identifyParams.shift();
/* To send revenue, you need to pass an object to the command:
*
* {
* id: 'product_id', // required
* price: 10.88, // required
* quantity: 1,
* revenueType: 'purchase',
* eventProperties: {'someKey': 'someValue}
* }
*
*/
var revenue = function(amplitudeInstance, args) {
args = args.shift();
// Validate revenue args
if (!args.price || !args.id) return;
// If not a valid "identify" command, return
if (identifyEnum.indexOf(cmd) === -1) return;
var revenue = new a.amplitude.Revenue()
.setProductId(args.id)
.setQuantity(args.quantity || 1)
.setPrice(args.price)
.setRevenueType(args.revenueType || '')
.setEventProperties(args.eventProperties || {});
identifyInstance[cmd].apply(identifyInstance, identifyParams);
});
amplitudeInstance.logRevenueV2(revenue);
};
amplitudeInstance.identify(identifyInstance);
};
// Build the command wrapper logic
a[p] = a[p] || function() {
/* To send revenue, you need to pass an object to the command:
*
* {
* id: 'product_id', // required
* price: 10.88, // required
* quantity: 1,
* revenueType: 'purchase',
* eventProperties: {'someKey': 'someValue}
* }
*
*/
var revenue = function (amplitudeInstance, args) {
args = args.shift();
// Validate revenue args
if (!args.price || !args.id) return;
// Build array out of arguments
var args = [].slice.call(arguments, 0);
// Pick the first argument as the command
var cmd = args.shift();
var revenue = new a.amplitude.Revenue()
.setProductId(args.id)
.setQuantity(args.quantity || 1)
.setPrice(args.price)
.setRevenueType(args.revenueType || '')
.setEventProperties(args.eventProperties || {});
/* Commands can be passed to instances with syntax:
* window._amplitude('instanceName.command', arguments)
*/
var instanceName = null;
var cmdParts = cmd.match(/^(.+)\.(.+)$/);
if (cmdParts && cmdParts.length === 3) {
instanceName = cmdParts[1];
cmd = cmdParts[2];
}
amplitudeInstance.logRevenueV2(revenue);
};
// If cmd is not one of the available ones, return
if (eventEnum.indexOf(cmd) === -1) return;
// Build the command wrapper logic
a[p] =
a[p] ||
function () {
// Build array out of arguments
var args = [].slice.call(arguments, 0);
// Fetch reference to instance
var amplitudeInstance = a.amplitude.getInstance(instanceName);
// Pick the first argument as the command
var cmd = args.shift();
// Handle Revenue separately
if (cmd === 'revenue') return revenue(amplitudeInstance, args);
/* Commands can be passed to instances with syntax:
* window._amplitude('instanceName.command', arguments)
*/
var instanceName = null;
var cmdParts = cmd.match(/^(.+)\.(.+)$/);
if (cmdParts && cmdParts.length === 3) {
instanceName = cmdParts[1];
cmd = cmdParts[2];
}
// Handle Identify separately
if (cmd === 'identify') return identify(amplitudeInstance, args);
// If cmd is not one of the available ones, return
if (eventEnum.indexOf(cmd) === -1) return;
// Otherwise call the method and pass the arguments
return amplitudeInstance[cmd].apply(amplitudeInstance, args);
// Fetch reference to instance
var amplitudeInstance = a.amplitude.getInstance(instanceName);
// Handle Revenue separately
if (cmd === 'revenue') return revenue(amplitudeInstance, args);
// Handle Identify separately
if (cmd === 'identify') return identify(amplitudeInstance, args);
// Otherwise call the method and pass the arguments
return amplitudeInstance[cmd].apply(amplitudeInstance, args);
};
})(window, '_amplitude')
/* Amplitude wrapper end */
})(window, '_amplitude');
/* Amplitude wrapper end */
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc