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

@amplitude/amplitude-js-gtm

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 2.0.2 to 3.0.0-beta.1

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

(()=>{"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}},i=t.createElement("script");i.type="text/javascript",i.integrity="sha384-VuGgAcmMrGHihvjXxxBVMIqoDFXc8/PO9q/08kCgq4Wn1iPnSmUbI3xhXaFozVFv",i.crossOrigin="anonymous",i.async=!0,i.src="https://cdn.amplitude.com/libs/amplitude-8.18.1-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 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){e.amplitude.getInstance().setLibrary("amplitude-js-gtm","2.0.2");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")})();
!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.id){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": "2.0.2",
"version": "3.0.0-beta.1",
"description": "Amplitude JS SDK Wrapper for use with Google Tag Manager",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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

# Amplitude JavaScript SDK wrapper for Google Tag Manager
# Amplitude JavaScript SDK wrapper V2 for Google Tag Manager
The purpose of this wrapper is to provide a JavaScript interface for interacting with the `window.amplitude` client.

@@ -8,6 +8,71 @@

Amplitude's [JavaScript SDK](https://developers.amplitude.com/docs/javascript) makes use of JavaScript features which are not permitted by the sandbox of GTM's custom templates (e.g. object instances initiated with the `new` keyword, `this` and `prototype`, custom parameters on the `<script>` element, etc.).
Amplitude's [Browser SDK](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/) makes use of JavaScript features which are not permitted by the sandbox of GTM's custom templates (e.g. object instances initiated with the `new` keyword, `this` and `prototype`, custom parameters on the `<script>` element, etc.).
Thus, in order to interact with Amplitude's JavaScript SDK via Google Tag Manager's custom templates (or any other context where the aforementioned JavaScript features cannot be used), this wrapper is required.
# Breaking changes in V2
This wrapper abandonds the [legacy SDK](https://www.docs.developers.amplitude.com/data/sdks/javascript/) and instead loads the [Marketing Analytics Browser SDK](https://www.docs.developers.amplitude.com/data/sdks/javascript/).
In addition to the [changes in the general usage of the SDK](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/migration/), there are some **breaking changes** in this wrapper itself.
## Instance names are no longer used
It is no longer possible to create unique instances of the `amplitude` tracking interface.
Commands need to provided as-is, without the instance prefix.
V1:
```
window._amplitude(
'myInstance.setOptOut',
true
);
```
V2:
```
window._amplitude(
'setOptOut',
true
);
```
## Deprecated event names
The following event names have been either completely removed or they have a new name in this wrapper.
| Event in V1 | Event in V2 |
|-|-|
| `isNewSession` | N/A |
| `setUserProperties` | `identify` |
| `clearUserProperties` | `identify` |
| `regenerateDeviceId` | `reset` |
| `setVersionName` | N/A |
| `logEvent` | `track` |
| `logEventWithTimestamp` | `track` |
| `logEventWithGroups` | `track` |
## Change to `productId` in the `revenue` call
The syntax of the `revenue` wrapper call has changed slightly, and the product ID is now passed with the `productId` key rather than `id`.
V1:
```
window._amplitude(
'revenue',
{
id: 'product_id',
...
}
);
```
V2:
```
window._amplitude(
'revenue',
{
productId: 'product_id',
...
}
);
```
# How it works

@@ -18,4 +83,2 @@ When the wrapper JavaScript is loaded in the browser, the global method `window._amplitude()` is created for interacting with the wrapper.

If this command name is prefixed with `<string>.`, then `<string>` will be used as the [instance name](https://developers.amplitude.com/docs/javascript#initialization). After the command, all additional arguments are processed as arguments to the command method itself.
For example, to initialize a tracker with an API key, a user ID, and some custom options, you can use this wrapper command:

@@ -25,6 +88,6 @@

window._amplitude(
'myTracker.init', // Run the init command and create a named instance "myTracker"
'abcd1234', // The API key
'user123', // (optional) User ID
{includeGclid: true, cookieName: 'amplitude_custom_cookie'} // (optional) Additional options
'init', // Run the init command
'abcd1234', // The API key
'user123', // (optional) User ID
{trackingOptions: {ipAddress: false}, appVersion: '2.0.1'} // (optional) Additional options
);

@@ -34,6 +97,8 @@ ```

## `init`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientinit)
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#initialize-the-sdk)
Use this command to initialize a tracker instance.
See [this specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#configuration) for what you can pass in the `configOptions` object.
Example:

@@ -43,121 +108,149 @@ ```

window._amplitude(
'init',
'abcd1234'
'init',
'abcd1234',
null,
configOptions
);
```
## `setOptOut`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientsetoptout)
## `track`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#track-an-event)
Opt current user out of tracking.
Use this command to track an event.
Example:
```
// Track an event named 'custom_scroll' with some event properties, options, and a group
window._amplitude(
'setOptOut',
true // Set to true to opt user out of tracking
'track',
'custom_scroll',
{
scroll_depth: 90 // Event property
},
{
time: Date.now() - 50000, // Set event timestamp to 50 seconds in the past
plan: 'enterprise' // Set event-level group type to "plan" and group name to "enterprise"
}
);
```
## `isNewSession`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientisnewsession)
## `identify`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#user-properties)
Returns `true` if this is a new session. `false` otherwise.
Run user property operations for the current user. The 'identify' method utilizes a single parameter, which is an array of individual user property operations. Each operation is its own array, following this format:
Example:
```
window._amplitude('isNewSession');
// Wrapper array
[
// First command
['identifyCommand', 'userProperty', 'value'],
// Second command
['identifyCommand', 'userProperty', 'value'],
// etc.
[...]
]
```
## `getSessionId`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientgetsessionid)
The `identify` API processes the commands in the order they are in the argument array.
Returns the current session ID.
Supported `identifyCommand` values are: `add`, `append`, `prepend`, `set`, `setOnce`, `unset`, `preInsert`, `postInsert`, `clearAll`. The last one takes no parameters and can be used to remove all user properties from the user.
Example:
```
window._amplitude('getSessionId');
window._amplitude(
'identify',
[
['set', 'user_status', 'customer'],
['add', 'purchases', 1],
['append', 'purchased_products', 'product_123']
]
);
```
## `setSessionId`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientsetsessionid)
Set a new session ID. Format must be in **milliseconds** since epoch (UNIX time).
Example:
Example with `clearAll`:
```
window._amplitude(
'setSessionId',
1634547544137
'identify',
[
['clearAll']
]
);
```
## `setUserId`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientsetuserid)
## `setGroup`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#user-groups)
Set the current user ID. The user ID should be a string or `null`. Use the latter to reset the User ID.
Add user to a group or groups.
Example:
```
// Adds the user to groups "org_1" and "org_2" in orgId.
window._amplitude(
'setUserId',
'user_12345'
'setGroup',
'orgId',
['org_1', 'org_2']
);
```
## `setUserProperties`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientsetuserproperties)
## `groupIdentify`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#group-properties)
Set user properties.
Set or update properties of particular groups.
The method takes three parameters: a group type, a group name, and an array of property operations (see `identify` above).
Example:
```
// Sets the property "plan" to "enterprise" for the given group.
window._amplitude(
'setUserProperties',
{
user_type: 'customer',
loyalty_level: 'platinum'
}
'groupIdentify',
'myOrganization', // Group type
'myGroup', // Group name
[
['set', 'plan', 'enterprise']
]
);
```
## `clearUserProperties`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientclearuserproperties)
## `revenue`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#revenue-tracking)
Clear all the user properties for the current user.
Log a Revenue event with details about the product. The product details are passed as an object with `productId` and `price` being required keys, and `quantity`, `revenueType`, and `eventProperties` as optional.
Example:
```
window._amplitude('clearUserProperties');
window._amplitude(
'revenue',
{
productId: 'cool_t_shirt', // required
price: 10.88, // required
quantity: 1,
revenueType: 'purchase',
eventProperties: {'coupon_used': true}
}
);
```
## `setGroup`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientsetgroup)
## `flush`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#flush-the-event-buffer)
Add user to a group or groups.
Trigger the client to send the buffered events immediately.
Example:
```
// Adds the user to groups "org_1" and "org_2" in orgId.
window._amplitude(
'setGroup',
'orgId',
['org_1', 'org_2']
);
window._amplitude('flush');
```
## `regenerateDeviceId`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientregeneratedeviceid)
## `getUserId`
Returns the current user ID.
Reset the user's device ID. This is particularly useful in conjunction with `_amplitude('setUserId', null)`, in case you want to reset a user's identifiers completely.
Example:
```
window._amplitude('regenerateDeviceId');
window._amplitude('getUserId');
```
## `setDeviceId`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientsetdeviceid)
## `setUserId`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#custom-user-id)
Manually override the user's device ID. **Must not have the "." character**. Recommended format is [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier).
Set the current user ID. The user ID should be a string or `null`. Use the latter to reset the User ID.

@@ -167,24 +260,19 @@ Example:

window._amplitude(
'setDeviceId',
'abcd1234-defg-hij1-klm2-yt4t112dabdd'
'setUserId',
'user_12345'
);
```
## `setVersionName`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientsetversionname)
## `getSessionId`
Returns the current session ID.
Set the application version name.
Example:
```
window._amplitude(
'setVersionName',
'1.1.0'
);
window._amplitude('getSessionId');
```
## `logEvent`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientlogevent)
## `setSessionId`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#custom-session-id)
Log an event with optional parameters and callback functions.
Set a new session ID. Format must be in **milliseconds** since epoch (UNIX time).

@@ -194,27 +282,19 @@ Example:

window._amplitude(
'logEvent',
'Scroll To Content',
{content_id: 'home_hero_copy'}
'setSessionId',
1634547544137
);
```
## `logEventWithTimestamp`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientlogeventwithtimestamp)
## `getDeviceId`
Returns the current device ID.
Log an event with a custom timestamp. Timestamp should be **milliseconds** since epoch (UNIX time).
Example:
```
window._amplitude(
'logEvent',
'Scroll To Content',
{content_id: 'home_hero_copy'},
1634547544137
);
window._amplitude('getDeviceId');
```
## `logEventWithGroups`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/#amplitudeclientlogeventwithgroups)
## `setDeviceId`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#custom-device-id)
Log an event with specific groups.
Manually override the user's device ID. **Must not have the "." character**. Recommended format is [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier).

@@ -224,57 +304,39 @@ Example:

window._amplitude(
'logEventWithGroups',
'Scroll To Content',
{content_id: 'home_hero_copy'},
{orgId: 'org_2'}
'setDeviceId',
'abcd1234-defg-hij1-klm2-yt4t112dabdd'
);
```
## `revenue`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/Revenue/)
## `reset`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#reset-when-user-logs-out)
Log a Revenue event with details about the product. The product details are passed as an object with `id` and `price` being required keys, and `quantity`, `revenueType`, and `eventProperties` as optional.
Anonymize the user by setting the `userId` to `undefined` and setting the `deviceId` to a new UUID value.
Example:
```
window._amplitude(
'revenue',
{
id: 'cool_t_shirt', // required
price: 10.88, // required
quantity: 1,
revenueType: 'purchase',
eventProperties: {'coupon_used': true}
}
);
window._amplitude('reset');
```
## `identify`
[Link to specification](https://amplitude.github.io/Amplitude-JavaScript/Identify)
## `setOptOut`
[Link to specification](https://www.docs.developers.amplitude.com/data/sdks/typescript-browser/#opt-users-out-of-tracking)
Run user property operations for the current user. The 'identify' method utilizes a single parameter, which is an array of individual user property operations. Each operation is its own array, following this format:
Opt current user out of tracking.
Example:
```
// Wrapper array
[
// First command
['identifyCommand', 'userProperty', 'value'],
// Second command
['identifyCommand', 'userProperty', 'value'],
// etc.
[...]
]
window._amplitude(
'setOptOut',
true // Set to true to opt user out of tracking
);
```
The `identify` API processes the commands in the order they are in the argument array.
## `setTransport`
Set the transport type to one of `xhr`, `sendBeacon`, or `fetch`.
Supported `identifyCommand` values are: `add`, `append`, `prepend`, `set`, `setOnce`, `unset`, `preInsert`.
Example:
```
window._amplitude([
'identify',
['set', 'user_status', 'customer'],
['add', 'purchases', 1],
['append', 'purchased_products', 'product_123']
]);
```
window._amplitude(
'setTransportType',
'sendBeacon'
);
```

@@ -1,125 +0,109 @@

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-VuGgAcmMrGHihvjXxxBVMIqoDFXc8/PO9q/08kCgq4Wn1iPnSmUbI3xhXaFozVFv';
r.crossOrigin = 'anonymous';
r.async = true;
r.src = 'https://cdn.amplitude.com/libs/amplitude-8.18.1-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)));
! function() {
"use strict";
! function(e, t) {
var n = e.amplitude || {
_q: [],
_iq: []
};
}
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);
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)
}();
/* Amplitude JavaScript SDK end */
/* Amplitude Wrapper begin */
(function (a, p) {
(function(a,p) {
// If window.amplitude doesn't exist, return
if (!a.amplitude || typeof a.amplitude.getInstance !== 'function') return;
if (!a.amplitude || typeof a.amplitude.init !== 'function') return;
a.amplitude.getInstance().setLibrary('amplitude-js-gtm', version);
// Enumerate available events
var eventEnum = [
'init',
'setOptOut',
'isNewSession',
'getSessionId',
'setSessionId',
'setUserId',
'setUserProperties',
'clearUserProperties',
'setGroup',
'regenerateDeviceId',
'setDeviceId',
'setVersionName',
'logEvent',
'logEventWithTimestamp',
'logEventWithGroups',
'revenue',
'identify',
'init',
'track',
'identify',
'setGroup',
'groupIdentify',
'revenue',
'flush',
'getUserId',
'setUserId',
'getSessionId',
'setSessionId',
'setDeviceId',
'getDeviceId',
'reset',
'setOptOut',
'setTransport'
];
var identifyEnum = ['add', 'append', 'prepend', 'set', 'setOnce', 'unset', 'preInsert'];
var identifyEnum = [
'add',
'append',
'clearAll',
'prepend',
'set',
'setOnce',
'remove',
'preInsert',
'postInsert'
];
/* To work with the identify API, pass an array of identify operation (each an array in itself)
/* To work with the identify API, pass an array of identify operations (each an array in itself)
* with the command and parameters included.
*
* window._amplitude('<instanceName.>identify', [
* window._amplitude('identify', [
* ['add', 'someUserProp', 1],

@@ -131,25 +115,59 @@ * ['add', 'someOtherUserProp', 2],

*/
var identify = function (amplitudeInstance, args) {
var identifyInstance = new a.amplitude.Identify();
var identify = function(args, group) {
args = args.shift();
// Validate identify args
if (!Array.isArray(args) || args.length === 0) return;
// Validate identify args
if (!Array.isArray(args) || args.length === 0) return;
var identifyInstance = new a.amplitude.Identify();
// Loop through the commands array and execute each
args[0].forEach(function (identifyParams) {
var cmd = identifyParams.shift();
// Loop through the commands array and execute each
args.forEach(function(identifyParams) {
// If the operation is not in array format, return
if (!Array.isArray(identifyParams)) return;
// If not a valid "identify" command, return
if (identifyEnum.indexOf(cmd) === -1) return;
var cmd = identifyParams.shift();
identifyInstance[cmd].apply(identifyInstance, identifyParams);
});
// If not a valid "identify" command, return
if (identifyEnum.indexOf(cmd) === -1) return;
identifyInstance[cmd].apply(identifyInstance, identifyParams);
});
amplitudeInstance.identify(identifyInstance);
// If this API is used with groupIdentify, return the Identify object
if (group === true) return identifyInstance;
a.amplitude.identify(identifyInstance);
};
/* The groupIdentify API is similar to identify, except you also need to collect
* the group name and type in addition to the Identify array.
*
* window._amplitude(
* 'groupIdentify',
* 'groupType',
* 'groupName',
* [
* ['add', 'someGroupUserProp', 1],
* ['prepend', 'someOtherGroupUserProp', 'someValue']
* ]
* );
*
*/
var groupIdentify = function(args) {
// Validate the arguments
if (args.length < 3) return;
if (typeof args[0] !== 'string' || typeof args[1] !== 'string') return;
if (!Array.isArray(args[2]) || args[2].length === 0) return;
// Get the Identify instance object
var groupIdentifyInstance = identify([args[2]], true);
a.amplitude.groupIdentify(args[0], args[1], groupIdentifyInstance);
};
/* To send revenue, you need to pass an object to the command:
*
* {
* id: 'product_id', // required
* productId: 'product_id', // required
* price: 10.88, // required

@@ -160,55 +178,45 @@ * quantity: 1,

* }
*
*
*/
var revenue = function (amplitudeInstance, args) {
args = args.shift();
// Validate revenue args
if (!args.price || !args.id) return;
var revenue = function(args) {
args = args.shift();
// Validate revenue args
if (!args.price || !args.id) return;
var revenue = new a.amplitude.Revenue()
.setProductId(args.id)
.setQuantity(args.quantity || 1)
.setPrice(args.price)
.setRevenueType(args.revenueType || '')
.setEventProperties(args.eventProperties || {});
var revenue = new a.amplitude.Revenue()
.setProductId(args.productId)
.setQuantity(args.quantity || 1)
.setPrice(args.price)
.setRevenueType(args.revenueType || '')
.setEventProperties(args.eventProperties || {});
amplitudeInstance.logRevenueV2(revenue);
a.amplitude.revenue(revenue);
};
// Build the command wrapper logic
a[p] =
a[p] ||
function () {
a[p] = a[p] || function() {
// Build array out of arguments
var args = [].slice.call(arguments, 0);
// Pick the first argument as the command
var cmd = args.shift();
/* 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];
}
// If cmd is not one of the available ones, return
if (eventEnum.indexOf(cmd) === -1) return;
// Fetch reference to instance
var amplitudeInstance = a.amplitude.getInstance(instanceName);
// Handle Revenue separately
if (cmd === 'revenue') return revenue(amplitudeInstance, args);
if (cmd === 'revenue') return revenue(args);
// Handle Identify separately
if (cmd === 'identify') return identify(amplitudeInstance, args);
if (cmd === 'identify') return identify(args);
// Handle GroupIdentify separately
if (cmd === 'groupIdentify') return groupIdentify(args);
// Otherwise call the method and pass the arguments
return amplitudeInstance[cmd].apply(amplitudeInstance, args);
};
})(window, '_amplitude');
/* Amplitude wrapper end */
return a.amplitude[cmd].apply(this, args);
};
})(window, '_amplitude')
/* Amplitude wrapper end */