@amplitude/plugin-web-attribution-browser 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ <p align="center">
2
+ <a href="https://amplitude.com" target="_blank" align="center">
3
+ <img src="https://static.amplitude.com/lightning/46c85bfd91905de8047f1ee65c7c93d6fa9ee6ea/static/media/amplitude-logo-with-text.4fb9e463.svg" width="280">
4
+ </a>
5
+ <br />
6
+ </p>
7
+
8
+ # @amplitude/plugin-web-attribution-browser
9
+
10
+ Official Browser SDK plugin for web attribution tracking
11
+
12
+ ## Installation
13
+
14
+ This package is published on NPM registry and is available to be installed using npm and yarn.
15
+
16
+ ```sh
17
+ # npm
18
+ npm install @amplitude/plugin-web-attribution-browser
19
+
20
+ # yarn
21
+ yarn add @amplitude/plugin-web-attribution-browser
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ This plugin works on top of Amplitude Browser SDK and adds web attribution tracking features to built-in features. To use this plugin, you need to install `@amplitude/analytics-browser` version `v1.4.0` or later.
27
+
28
+ ### 1. Import Amplitude packages
29
+
30
+ * `@amplitude/analytics-browser`
31
+ * `@amplitude/plugin-web-attribution-browser`
32
+
33
+ ```typescript
34
+ import * as amplitude from '@amplitude/analytics-browser';
35
+ import { webAttributionPlugin } from '@amplitude/plugin-web-attribution-browser';
36
+ ```
37
+
38
+ ### 2. Instantiate page view plugin
39
+
40
+ The plugin requires 1 parameter, which is the `amplitude` instance. The plugin also accepts an optional second parameter, which is an `Object` to configure the plugin based on your use case.
41
+
42
+ ```typescript
43
+ const webAttributionTracking = webAttributionPlugin(amplitude, {
44
+ disabled: undefined,
45
+ excludeReferrers: undefined,
46
+ initialEmptyValue: undefined,
47
+ resetSessionOnNewCampaign: undefined,
48
+ });
49
+ ```
50
+
51
+ #### Options
52
+
53
+ |Name|Type|Default|Description|
54
+ |-|-|-|-|
55
+ |`disabled`|`boolean`|`false`|Use this option to enable or disable web attribution tracking. By default, upon installing this plugin, web attribution tracking is enabled.|
56
+ |`excludeReferrers`|`string[]`|`[]`|Use this option to prevent the plugin from tracking campaigns parameters from specific referrers. For example: `subdomain.domain.com`.|
57
+ |`initialEmptyValue`|`string`|`"EMPTY"`|Use this option to specify empty values for [first-touch attribution](https://www.docs.developers.amplitude.com/data/sdks/marketing-analytics-browser/#first-touch-attribution).|
58
+ |`resetSessionOnNewCampaign`|`boolean`|`false`|Use this option to control whether a new session should start on a new campaign.|
59
+
60
+ ### 3. Install plugin to Amplitude SDK
61
+
62
+ ```typescript
63
+ amplitude.add(webAttributionTracking);
64
+ ```
65
+
66
+ ### 4. Initialize Amplitude SDK
67
+
68
+ ```typescript
69
+ amplitude.init('API_KEY');
70
+ ```
71
+
72
+ ## Resulting web attribution event
73
+
74
+ This plugin tracks campaign parameters based on your configuration. A web attribution event is composed of the following values:
75
+
76
+ #### Event type
77
+ * `"$idenfity"`
78
+
79
+ #### User properties
80
+
81
+ |Property|Description|
82
+ |-|-|
83
+ |`utm_source`|URL query parameter value for `utm_source`|
84
+ |`utm_medium`|URL query parameter value for `utm_medium`|
85
+ |`utm_campaign`|URL query parameter value for `utm_campaign`|
86
+ |`utm_term`|URL query parameter value for `utm_term`|
87
+ |`utm_content`|URL query parameter value for `utm_content`|
88
+ |`referrer`|Referring webstite or `document.referrer`|
89
+ |`referring_domain`|Referring website's domain, including subdomain|
90
+ |`dclid`|URL query parameter value for `dclid`|
91
+ |`gbraid`|URL query parameter value for `gbraid`|
92
+ |`gclid`|URL query parameter value for `gclid`|
93
+ |`fbclid`|URL query parameter value for `fbclid`|
94
+ |`ko_click_id`|URL query parameter value for `ko_click_id`|
95
+ |`msclkid`|URL query parameter value for `msclkid`|
96
+ |`ttclid`|URL query parameter value for `ttclid`|
97
+ |`twclid`|URL query parameter value for `twclid`|
98
+ |`wbraid`|URL query parameter value for `wbraid`|
@@ -1 +1 @@
1
- var webAttribution=function(e){"use strict";var t,r,n,i,o=function(){return o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};function a(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{s(n.next(e))}catch(e){o(e)}}function u(e){try{s(n.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(t||(t={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(n||(n={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(i||(i={}));var c=function(){var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0;return(null==e?void 0:e.location.search)?e.location.search.substring(1).split("&").filter(Boolean).reduce((function(e,t){var r=t.split("=",2),n=p(r[0]),i=p(r[1]);return i?(e[n]=i,e):e}),{}):{}},p=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f={utm_source:void 0,utm_medium:void 0,utm_campaign:void 0,utm_term:void 0,utm_content:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},l=function(){function e(){}return e.prototype.parse=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){return[2,o(o(o(o({},f),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=c();return{utm_source:e.utm_source,utm_medium:e.utm_medium,utm_campaign:e.utm_campaign,utm_term:e.utm_term,utm_content:e.utm_content}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=c();return(e={}).dclid=t.dclid,e.fbclid=t.fbclid,e.gbraid=t.gbraid,e.gclid=t.gclid,e.ko_click_id=t.ko_click_id,e.msclkid=t.msclkid,e.ttclid=t.ttclid,e.twclid=t.twclid,e.wbraid=t.wbraid,e},e}(),d="AMP",h=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!g(t,r))return!1}return!0},g=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),a=o.next();!a.done;a=o.next()){var u=a.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&h(u);else if(!["number","string"].includes(typeof u))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return h(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},v=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return o({},this._properties)},e.prototype.set=function(e,r){return this._safeSet(t.SET,e,r),this},e.prototype.setOnce=function(e,r){return this._safeSet(t.SET_ONCE,e,r),this},e.prototype.append=function(e,r){return this._safeSet(t.APPEND,e,r),this},e.prototype.prepend=function(e,r){return this._safeSet(t.PREPEND,e,r),this},e.prototype.postInsert=function(e,r){return this._safeSet(t.POSTINSERT,e,r),this},e.prototype.preInsert=function(e,r){return this._safeSet(t.PREINSERT,e,r),this},e.prototype.remove=function(e,r){return this._safeSet(t.REMOVE,e,r),this},e.prototype.add=function(e,r){return this._safeSet(t.ADD,e,r),this},e.prototype.unset=function(e){return this._safeSet(t.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[t.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,r,n){return void 0===this._properties[t.CLEAR_ALL]&&(!this._propertySet.has(r)&&(e===t.ADD?"number"==typeof n:e===t.UNSET||e===t.REMOVE||g(r,n)))},e}(),y=function(){function e(e,t){var r,n;this.storage=t.storage,this.storageKey=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[d,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new l,this.track=t.track,this.onNewCampaign=t.onNewCampaign,this.disabled=Boolean(t.disabled),this.trackNewCampaigns=Boolean(t.trackNewCampaigns),this.trackPageViews=Boolean(t.trackPageViews),this.excludeReferrers=null!==(r=t.excludeReferrers)&&void 0!==r?r:[],"undefined"!=typeof location&&this.excludeReferrers.unshift(location.hostname),this.initialEmptyValue=null!==(n=t.initialEmptyValue)&&void 0!==n?n:"EMPTY"}return e.prototype.isNewCampaign=function(e,t){e.referrer;var r=a(e,["referrer"]),n=t||{};n.referrer;var i=a(n,["referrer"]),o=Boolean(r.referring_domain&&this.excludeReferrers.includes(r.referring_domain)),u=JSON.stringify(r)!==JSON.stringify(i);return!o&&(!t||u)},e.prototype.saveCampaignToStorage=function(e){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.storage.set(this.storageKey,e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getCampaignFromStorage=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.storage.get(this.storageKey)];case 1:return[2,e.sent()]}}))}))},e.prototype.createCampaignEvent=function(e){var t,r,i=this,a=o(o({},f),e),u=Object.entries(a).reduce((function(e,t){var r=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}(t,2),n=r[0],o=r[1];return e.setOnce("initial_".concat(n),o||i.initialEmptyValue),o?e.set(n,o):e.unset(n)}),new v),s={event_type:"Page View",event_properties:{page_title:"undefined"!=typeof document&&document.title||"",page_location:"undefined"!=typeof location&&location.href||"",page_path:"undefined"!=typeof location&&location.pathname||""}};return o(o({},(t=u,o(o({},r),{event_type:n.IDENTIFY,user_properties:t.getUserProperties()}))),this.trackPageViews&&s)},e.prototype.send=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return this.disabled?[2]:[4,this.parser.parse()];case 1:return t=n.sent(),[4,this.getCampaignFromStorage()];case 2:if(r=n.sent(),!e){if(!this.trackNewCampaigns||!this.isNewCampaign(t,r))return[2];this.onNewCampaign(t)}return[4,this.track(this.createCampaignEvent(t))];case 3:return n.sent(),[4,this.saveCampaignToStorage(t)];case 4:return n.sent(),[2]}}))}))},e}(),m=function(){function e(e,t,r){this.campaignTracker=new y(e,o(o({},r),{trackPageViews:!1,track:function(){return Promise.resolve()},onNewCampaign:function(){return function(){}},storage:t}))}return e.prototype.createCampaignEvent=function(e){return this.campaignTracker.createCampaignEvent(e)},e.prototype.onPageChange=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return t=e,[4,this.getCurrentState()];case 1:return[4,t.apply(void 0,[n.sent()])];case 2:return n.sent(),[4,this.getCurrentState()];case 3:return(r=n.sent()).isNewCampaign&&this.campaignTracker.saveCampaignToStorage(r.currentCampaign),[2]}}))}))},e.prototype.getCurrentState=function(){return u(this,void 0,void 0,(function(){var e,t,r,n;return s(this,(function(i){switch(i.label){case 0:return[4,this.campaignTracker.parser.parse()];case 1:return e=i.sent(),r=(t=this.campaignTracker).isNewCampaign,n=[e],[4,this.campaignTracker.getCampaignFromStorage()];case 2:return[2,{isNewCampaign:r.apply(t,n.concat([i.sent()])),currentCampaign:e}]}}))}))},e}(),b=function(e,t){return void 0===t&&(t={}),{name:"web-attribution",type:i.BEFORE,setup:function(r){return u(void 0,void 0,void 0,(function(){var n,i,a;return s(this,(function(c){return r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser"),(null===(a=r.attribution)||void 0===a?void 0:a.disabled)||(r.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser"),r.attribution={disabled:!0}),n=r.cookieStorage,(i=new m(r.apiKey,n,o({},t))).onPageChange((function(n){var o=n.isNewCampaign,a=n.currentCampaign;return u(void 0,void 0,void 0,(function(){return s(this,(function(n){return o&&(t.resetSessionOnNewCampaign&&(e.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign")),r.loggerProvider.log("Tracking new campaign event"),e.track(i.createCampaignEvent(a))),[2]}))}))})),[2]}))}))},execute:function(e){return u(void 0,void 0,void 0,(function(){return s(this,(function(t){return[2,e]}))}))}}},_=Object.freeze({__proto__:null});return e.Types=_,e.plugin=b,e.webAttributionPlugin=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
1
+ var webAttribution=function(e){"use strict";var t,r,n,i,o=function(){return o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};function a(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{s(n.next(e))}catch(e){o(e)}}function u(e){try{s(n.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(t||(t={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(n||(n={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(i||(i={}));var c=function(){var e,t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0;return(null===(e=null==t?void 0:t.location)||void 0===e?void 0:e.search)?t.location.search.substring(1).split("&").filter(Boolean).reduce((function(e,t){var r=t.split("=",2),n=p(r[0]),i=p(r[1]);return i?(e[n]=i,e):e}),{}):{}},p=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f={utm_source:void 0,utm_medium:void 0,utm_campaign:void 0,utm_term:void 0,utm_content:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},l=function(){function e(){}return e.prototype.parse=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){return[2,o(o(o(o({},f),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=c();return{utm_source:e.utm_source,utm_medium:e.utm_medium,utm_campaign:e.utm_campaign,utm_term:e.utm_term,utm_content:e.utm_content}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=c();return(e={}).dclid=t.dclid,e.fbclid=t.fbclid,e.gbraid=t.gbraid,e.gclid=t.gclid,e.ko_click_id=t.ko_click_id,e.msclkid=t.msclkid,e.ttclid=t.ttclid,e.twclid=t.twclid,e.wbraid=t.wbraid,e},e}(),d="AMP",h=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!g(t,r))return!1}return!0},g=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),a=o.next();!a.done;a=o.next()){var u=a.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&h(u);else if(!["number","string"].includes(typeof u))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return h(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},v=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return o({},this._properties)},e.prototype.set=function(e,r){return this._safeSet(t.SET,e,r),this},e.prototype.setOnce=function(e,r){return this._safeSet(t.SET_ONCE,e,r),this},e.prototype.append=function(e,r){return this._safeSet(t.APPEND,e,r),this},e.prototype.prepend=function(e,r){return this._safeSet(t.PREPEND,e,r),this},e.prototype.postInsert=function(e,r){return this._safeSet(t.POSTINSERT,e,r),this},e.prototype.preInsert=function(e,r){return this._safeSet(t.PREINSERT,e,r),this},e.prototype.remove=function(e,r){return this._safeSet(t.REMOVE,e,r),this},e.prototype.add=function(e,r){return this._safeSet(t.ADD,e,r),this},e.prototype.unset=function(e){return this._safeSet(t.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[t.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,r,n){return void 0===this._properties[t.CLEAR_ALL]&&(!this._propertySet.has(r)&&(e===t.ADD?"number"==typeof n:e===t.UNSET||e===t.REMOVE||g(r,n)))},e}(),y=function(){function e(e,t){var r,n;this.storage=t.storage,this.storageKey=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[d,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new l,this.track=t.track,this.onNewCampaign=t.onNewCampaign,this.disabled=Boolean(t.disabled),this.trackNewCampaigns=Boolean(t.trackNewCampaigns),this.trackPageViews=Boolean(t.trackPageViews),this.excludeReferrers=null!==(r=t.excludeReferrers)&&void 0!==r?r:[],"undefined"!=typeof location&&this.excludeReferrers.unshift(location.hostname),this.initialEmptyValue=null!==(n=t.initialEmptyValue)&&void 0!==n?n:"EMPTY"}return e.prototype.isNewCampaign=function(e,t){e.referrer;var r=a(e,["referrer"]),n=t||{};n.referrer;var i=a(n,["referrer"]),o=Boolean(r.referring_domain&&this.excludeReferrers.includes(r.referring_domain)),u=JSON.stringify(r)!==JSON.stringify(i);return!o&&(!t||u)},e.prototype.saveCampaignToStorage=function(e){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.storage.set(this.storageKey,e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getCampaignFromStorage=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.storage.get(this.storageKey)];case 1:return[2,e.sent()]}}))}))},e.prototype.createCampaignEvent=function(e){var t,r,i=this,a=o(o({},f),e),u=Object.entries(a).reduce((function(e,t){var r=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}(t,2),n=r[0],o=r[1];return e.setOnce("initial_".concat(n),o||i.initialEmptyValue),o?e.set(n,o):e.unset(n)}),new v),s={event_type:"Page View",event_properties:{page_title:"undefined"!=typeof document&&document.title||"",page_location:"undefined"!=typeof location&&location.href||"",page_path:"undefined"!=typeof location&&location.pathname||""}};return o(o({},(t=u,o(o({},r),{event_type:n.IDENTIFY,user_properties:t.getUserProperties()}))),this.trackPageViews&&s)},e.prototype.send=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return this.disabled?[2]:[4,this.parser.parse()];case 1:return t=n.sent(),[4,this.getCampaignFromStorage()];case 2:if(r=n.sent(),!e){if(!this.trackNewCampaigns||!this.isNewCampaign(t,r))return[2];this.onNewCampaign(t)}return[4,this.track(this.createCampaignEvent(t))];case 3:return n.sent(),[4,this.saveCampaignToStorage(t)];case 4:return n.sent(),[2]}}))}))},e}(),m=function(){function e(e,t,r){this.campaignTracker=new y(e,o(o({},r),{trackPageViews:!1,track:function(){return Promise.resolve()},onNewCampaign:function(){return function(){}},storage:t}))}return e.prototype.createCampaignEvent=function(e){return this.campaignTracker.createCampaignEvent(e)},e.prototype.onPageChange=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return t=e,[4,this.getCurrentState()];case 1:return[4,t.apply(void 0,[n.sent()])];case 2:return n.sent(),[4,this.getCurrentState()];case 3:return(r=n.sent()).isNewCampaign&&this.campaignTracker.saveCampaignToStorage(r.currentCampaign),[2]}}))}))},e.prototype.getCurrentState=function(){return u(this,void 0,void 0,(function(){var e,t,r,n;return s(this,(function(i){switch(i.label){case 0:return[4,this.campaignTracker.parser.parse()];case 1:return e=i.sent(),r=(t=this.campaignTracker).isNewCampaign,n=[e],[4,this.campaignTracker.getCampaignFromStorage()];case 2:return[2,{isNewCampaign:r.apply(t,n.concat([i.sent()])),currentCampaign:e}]}}))}))},e}(),b=function(e,t){return void 0===t&&(t={}),{name:"web-attribution",type:i.BEFORE,setup:function(r){return u(void 0,void 0,void 0,(function(){var n,i,a;return s(this,(function(c){return r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser"),(null===(a=r.attribution)||void 0===a?void 0:a.disabled)||(r.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser"),r.attribution={disabled:!0}),n=r.cookieStorage,(i=new m(r.apiKey,n,o({},t))).onPageChange((function(n){var o=n.isNewCampaign,a=n.currentCampaign;return u(void 0,void 0,void 0,(function(){return s(this,(function(n){return o&&(t.resetSessionOnNewCampaign&&(e.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign")),r.loggerProvider.log("Tracking new campaign event"),e.track(i.createCampaignEvent(a))),[2]}))}))})),[2]}))}))},execute:function(e){return u(void 0,void 0,void 0,(function(){return s(this,(function(t){return[2,e]}))}))}}},_=Object.freeze({__proto__:null});return e.Types=_,e.plugin=b,e.webAttributionPlugin=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
Binary file
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,(function(e){"use strict";var t,r,n,i,o=function(){return o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};function a(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{s(n.next(e))}catch(e){o(e)}}function u(e){try{s(n.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(t||(t={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(n||(n={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(i||(i={}));var c=function(){var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0;return(null==e?void 0:e.location.search)?e.location.search.substring(1).split("&").filter(Boolean).reduce((function(e,t){var r=t.split("=",2),n=p(r[0]),i=p(r[1]);return i?(e[n]=i,e):e}),{}):{}},p=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f={utm_source:void 0,utm_medium:void 0,utm_campaign:void 0,utm_term:void 0,utm_content:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},l=function(){function e(){}return e.prototype.parse=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){return[2,o(o(o(o({},f),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=c();return{utm_source:e.utm_source,utm_medium:e.utm_medium,utm_campaign:e.utm_campaign,utm_term:e.utm_term,utm_content:e.utm_content}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=c();return(e={}).dclid=t.dclid,e.fbclid=t.fbclid,e.gbraid=t.gbraid,e.gclid=t.gclid,e.ko_click_id=t.ko_click_id,e.msclkid=t.msclkid,e.ttclid=t.ttclid,e.twclid=t.twclid,e.wbraid=t.wbraid,e},e}(),d="AMP",h=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!g(t,r))return!1}return!0},g=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),a=o.next();!a.done;a=o.next()){var u=a.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&h(u);else if(!["number","string"].includes(typeof u))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return h(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},v=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return o({},this._properties)},e.prototype.set=function(e,r){return this._safeSet(t.SET,e,r),this},e.prototype.setOnce=function(e,r){return this._safeSet(t.SET_ONCE,e,r),this},e.prototype.append=function(e,r){return this._safeSet(t.APPEND,e,r),this},e.prototype.prepend=function(e,r){return this._safeSet(t.PREPEND,e,r),this},e.prototype.postInsert=function(e,r){return this._safeSet(t.POSTINSERT,e,r),this},e.prototype.preInsert=function(e,r){return this._safeSet(t.PREINSERT,e,r),this},e.prototype.remove=function(e,r){return this._safeSet(t.REMOVE,e,r),this},e.prototype.add=function(e,r){return this._safeSet(t.ADD,e,r),this},e.prototype.unset=function(e){return this._safeSet(t.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[t.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,r,n){return void 0===this._properties[t.CLEAR_ALL]&&(!this._propertySet.has(r)&&(e===t.ADD?"number"==typeof n:e===t.UNSET||e===t.REMOVE||g(r,n)))},e}(),y=function(){function e(e,t){var r,n;this.storage=t.storage,this.storageKey=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[d,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new l,this.track=t.track,this.onNewCampaign=t.onNewCampaign,this.disabled=Boolean(t.disabled),this.trackNewCampaigns=Boolean(t.trackNewCampaigns),this.trackPageViews=Boolean(t.trackPageViews),this.excludeReferrers=null!==(r=t.excludeReferrers)&&void 0!==r?r:[],"undefined"!=typeof location&&this.excludeReferrers.unshift(location.hostname),this.initialEmptyValue=null!==(n=t.initialEmptyValue)&&void 0!==n?n:"EMPTY"}return e.prototype.isNewCampaign=function(e,t){e.referrer;var r=a(e,["referrer"]),n=t||{};n.referrer;var i=a(n,["referrer"]),o=Boolean(r.referring_domain&&this.excludeReferrers.includes(r.referring_domain)),u=JSON.stringify(r)!==JSON.stringify(i);return!o&&(!t||u)},e.prototype.saveCampaignToStorage=function(e){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.storage.set(this.storageKey,e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getCampaignFromStorage=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.storage.get(this.storageKey)];case 1:return[2,e.sent()]}}))}))},e.prototype.createCampaignEvent=function(e){var t,r,i=this,a=o(o({},f),e),u=Object.entries(a).reduce((function(e,t){var r=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}(t,2),n=r[0],o=r[1];return e.setOnce("initial_".concat(n),o||i.initialEmptyValue),o?e.set(n,o):e.unset(n)}),new v),s={event_type:"Page View",event_properties:{page_title:"undefined"!=typeof document&&document.title||"",page_location:"undefined"!=typeof location&&location.href||"",page_path:"undefined"!=typeof location&&location.pathname||""}};return o(o({},(t=u,o(o({},r),{event_type:n.IDENTIFY,user_properties:t.getUserProperties()}))),this.trackPageViews&&s)},e.prototype.send=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return this.disabled?[2]:[4,this.parser.parse()];case 1:return t=n.sent(),[4,this.getCampaignFromStorage()];case 2:if(r=n.sent(),!e){if(!this.trackNewCampaigns||!this.isNewCampaign(t,r))return[2];this.onNewCampaign(t)}return[4,this.track(this.createCampaignEvent(t))];case 3:return n.sent(),[4,this.saveCampaignToStorage(t)];case 4:return n.sent(),[2]}}))}))},e}(),m=function(){function e(e,t,r){this.campaignTracker=new y(e,o(o({},r),{trackPageViews:!1,track:function(){return Promise.resolve()},onNewCampaign:function(){return function(){}},storage:t}))}return e.prototype.createCampaignEvent=function(e){return this.campaignTracker.createCampaignEvent(e)},e.prototype.onPageChange=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return t=e,[4,this.getCurrentState()];case 1:return[4,t.apply(void 0,[n.sent()])];case 2:return n.sent(),[4,this.getCurrentState()];case 3:return(r=n.sent()).isNewCampaign&&this.campaignTracker.saveCampaignToStorage(r.currentCampaign),[2]}}))}))},e.prototype.getCurrentState=function(){return u(this,void 0,void 0,(function(){var e,t,r,n;return s(this,(function(i){switch(i.label){case 0:return[4,this.campaignTracker.parser.parse()];case 1:return e=i.sent(),r=(t=this.campaignTracker).isNewCampaign,n=[e],[4,this.campaignTracker.getCampaignFromStorage()];case 2:return[2,{isNewCampaign:r.apply(t,n.concat([i.sent()])),currentCampaign:e}]}}))}))},e}(),b=function(e,t){return void 0===t&&(t={}),{name:"web-attribution",type:i.BEFORE,setup:function(r){return u(void 0,void 0,void 0,(function(){var n,i,a;return s(this,(function(c){return r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser"),(null===(a=r.attribution)||void 0===a?void 0:a.disabled)||(r.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser"),r.attribution={disabled:!0}),n=r.cookieStorage,(i=new m(r.apiKey,n,o({},t))).onPageChange((function(n){var o=n.isNewCampaign,a=n.currentCampaign;return u(void 0,void 0,void 0,(function(){return s(this,(function(n){return o&&(t.resetSessionOnNewCampaign&&(e.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign")),r.loggerProvider.log("Tracking new campaign event"),e.track(i.createCampaignEvent(a))),[2]}))}))})),[2]}))}))},execute:function(e){return u(void 0,void 0,void 0,(function(){return s(this,(function(t){return[2,e]}))}))}}},_=Object.freeze({__proto__:null});e.Types=_,e.plugin=b,e.webAttributionPlugin=b,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,(function(e){"use strict";var t,r,n,i,o=function(){return o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};function a(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{s(n.next(e))}catch(e){o(e)}}function u(e){try{s(n.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(t||(t={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(n||(n={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(i||(i={}));var c=function(){var e,t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0;return(null===(e=null==t?void 0:t.location)||void 0===e?void 0:e.search)?t.location.search.substring(1).split("&").filter(Boolean).reduce((function(e,t){var r=t.split("=",2),n=p(r[0]),i=p(r[1]);return i?(e[n]=i,e):e}),{}):{}},p=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f={utm_source:void 0,utm_medium:void 0,utm_campaign:void 0,utm_term:void 0,utm_content:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},l=function(){function e(){}return e.prototype.parse=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){return[2,o(o(o(o({},f),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=c();return{utm_source:e.utm_source,utm_medium:e.utm_medium,utm_campaign:e.utm_campaign,utm_term:e.utm_term,utm_content:e.utm_content}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=c();return(e={}).dclid=t.dclid,e.fbclid=t.fbclid,e.gbraid=t.gbraid,e.gclid=t.gclid,e.ko_click_id=t.ko_click_id,e.msclkid=t.msclkid,e.ttclid=t.ttclid,e.twclid=t.twclid,e.wbraid=t.wbraid,e},e}(),d="AMP",h=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!g(t,r))return!1}return!0},g=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),a=o.next();!a.done;a=o.next()){var u=a.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&h(u);else if(!["number","string"].includes(typeof u))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return h(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},v=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return o({},this._properties)},e.prototype.set=function(e,r){return this._safeSet(t.SET,e,r),this},e.prototype.setOnce=function(e,r){return this._safeSet(t.SET_ONCE,e,r),this},e.prototype.append=function(e,r){return this._safeSet(t.APPEND,e,r),this},e.prototype.prepend=function(e,r){return this._safeSet(t.PREPEND,e,r),this},e.prototype.postInsert=function(e,r){return this._safeSet(t.POSTINSERT,e,r),this},e.prototype.preInsert=function(e,r){return this._safeSet(t.PREINSERT,e,r),this},e.prototype.remove=function(e,r){return this._safeSet(t.REMOVE,e,r),this},e.prototype.add=function(e,r){return this._safeSet(t.ADD,e,r),this},e.prototype.unset=function(e){return this._safeSet(t.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[t.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,r,n){return void 0===this._properties[t.CLEAR_ALL]&&(!this._propertySet.has(r)&&(e===t.ADD?"number"==typeof n:e===t.UNSET||e===t.REMOVE||g(r,n)))},e}(),y=function(){function e(e,t){var r,n;this.storage=t.storage,this.storageKey=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[d,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new l,this.track=t.track,this.onNewCampaign=t.onNewCampaign,this.disabled=Boolean(t.disabled),this.trackNewCampaigns=Boolean(t.trackNewCampaigns),this.trackPageViews=Boolean(t.trackPageViews),this.excludeReferrers=null!==(r=t.excludeReferrers)&&void 0!==r?r:[],"undefined"!=typeof location&&this.excludeReferrers.unshift(location.hostname),this.initialEmptyValue=null!==(n=t.initialEmptyValue)&&void 0!==n?n:"EMPTY"}return e.prototype.isNewCampaign=function(e,t){e.referrer;var r=a(e,["referrer"]),n=t||{};n.referrer;var i=a(n,["referrer"]),o=Boolean(r.referring_domain&&this.excludeReferrers.includes(r.referring_domain)),u=JSON.stringify(r)!==JSON.stringify(i);return!o&&(!t||u)},e.prototype.saveCampaignToStorage=function(e){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.storage.set(this.storageKey,e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getCampaignFromStorage=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.storage.get(this.storageKey)];case 1:return[2,e.sent()]}}))}))},e.prototype.createCampaignEvent=function(e){var t,r,i=this,a=o(o({},f),e),u=Object.entries(a).reduce((function(e,t){var r=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a}(t,2),n=r[0],o=r[1];return e.setOnce("initial_".concat(n),o||i.initialEmptyValue),o?e.set(n,o):e.unset(n)}),new v),s={event_type:"Page View",event_properties:{page_title:"undefined"!=typeof document&&document.title||"",page_location:"undefined"!=typeof location&&location.href||"",page_path:"undefined"!=typeof location&&location.pathname||""}};return o(o({},(t=u,o(o({},r),{event_type:n.IDENTIFY,user_properties:t.getUserProperties()}))),this.trackPageViews&&s)},e.prototype.send=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return this.disabled?[2]:[4,this.parser.parse()];case 1:return t=n.sent(),[4,this.getCampaignFromStorage()];case 2:if(r=n.sent(),!e){if(!this.trackNewCampaigns||!this.isNewCampaign(t,r))return[2];this.onNewCampaign(t)}return[4,this.track(this.createCampaignEvent(t))];case 3:return n.sent(),[4,this.saveCampaignToStorage(t)];case 4:return n.sent(),[2]}}))}))},e}(),m=function(){function e(e,t,r){this.campaignTracker=new y(e,o(o({},r),{trackPageViews:!1,track:function(){return Promise.resolve()},onNewCampaign:function(){return function(){}},storage:t}))}return e.prototype.createCampaignEvent=function(e){return this.campaignTracker.createCampaignEvent(e)},e.prototype.onPageChange=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return t=e,[4,this.getCurrentState()];case 1:return[4,t.apply(void 0,[n.sent()])];case 2:return n.sent(),[4,this.getCurrentState()];case 3:return(r=n.sent()).isNewCampaign&&this.campaignTracker.saveCampaignToStorage(r.currentCampaign),[2]}}))}))},e.prototype.getCurrentState=function(){return u(this,void 0,void 0,(function(){var e,t,r,n;return s(this,(function(i){switch(i.label){case 0:return[4,this.campaignTracker.parser.parse()];case 1:return e=i.sent(),r=(t=this.campaignTracker).isNewCampaign,n=[e],[4,this.campaignTracker.getCampaignFromStorage()];case 2:return[2,{isNewCampaign:r.apply(t,n.concat([i.sent()])),currentCampaign:e}]}}))}))},e}(),b=function(e,t){return void 0===t&&(t={}),{name:"web-attribution",type:i.BEFORE,setup:function(r){return u(void 0,void 0,void 0,(function(){var n,i,a;return s(this,(function(c){return r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser"),(null===(a=r.attribution)||void 0===a?void 0:a.disabled)||(r.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser"),r.attribution={disabled:!0}),n=r.cookieStorage,(i=new m(r.apiKey,n,o({},t))).onPageChange((function(n){var o=n.isNewCampaign,a=n.currentCampaign;return u(void 0,void 0,void 0,(function(){return s(this,(function(n){return o&&(t.resetSessionOnNewCampaign&&(e.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign")),r.loggerProvider.log("Tracking new campaign event"),e.track(i.createCampaignEvent(a))),[2]}))}))})),[2]}))}))},execute:function(e){return u(void 0,void 0,void 0,(function(){return s(this,(function(t){return[2,e]}))}))}}},_=Object.freeze({__proto__:null});e.Types=_,e.plugin=b,e.webAttributionPlugin=b,Object.defineProperty(e,"__esModule",{value:!0})}));
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/plugin-web-attribution-browser",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "",
5
5
  "author": "Amplitude Inc",
6
6
  "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
@@ -36,12 +36,12 @@
36
36
  "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@amplitude/analytics-client-common": "^0.3.3",
39
+ "@amplitude/analytics-client-common": "^0.3.4",
40
40
  "@amplitude/analytics-types": "^0.11.0",
41
41
  "tslib": "^2.3.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@amplitude/analytics-browser": "^1.5.7",
44
+ "@amplitude/analytics-browser": "^1.5.8",
45
45
  "@rollup/plugin-commonjs": "^21.0.2",
46
46
  "@rollup/plugin-node-resolve": "^13.1.3",
47
47
  "@rollup/plugin-typescript": "^8.3.1",
@@ -53,5 +53,5 @@
53
53
  "files": [
54
54
  "lib"
55
55
  ],
56
- "gitHead": "ac6a480f88b44ea2867c74d60630b7678a968d25"
56
+ "gitHead": "b1cf8c7d08e265ac733f5a775acf65da361dbe7b"
57
57
  }