@amplitude/plugin-web-attribution-browser 2.0.0-beta.1 → 2.0.0-beta.2
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/lib/cjs/web-attribution.d.ts.map +1 -1
- package/lib/cjs/web-attribution.js +1 -2
- package/lib/cjs/web-attribution.js.map +1 -1
- package/lib/esm/web-attribution.d.ts.map +1 -1
- package/lib/esm/web-attribution.js +1 -2
- package/lib/esm/web-attribution.js.map +1 -1
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/web-attribution.d.ts.map +1 -1
- package/package.json +5 -5
- package/lib/scripts/amplitude-min.js +0 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAW,MAAM,2BAA2B,CAAC;AAEhF,eAAO,MAAM,oBAAoB,EAAE,0BAuClC,CAAC"}
|
|
@@ -2,14 +2,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
2
2
|
exports.webAttributionPlugin = void 0;
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var analytics_client_common_1 = require("@amplitude/analytics-client-common");
|
|
5
|
-
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
6
5
|
var helpers_1 = require("./helpers");
|
|
7
6
|
var webAttributionPlugin = function (options) {
|
|
8
7
|
var _this = this;
|
|
9
8
|
if (options === void 0) { options = {}; }
|
|
10
9
|
var plugin = {
|
|
11
10
|
name: '@amplitude/plugin-web-attribution-browser',
|
|
12
|
-
type:
|
|
11
|
+
type: 'before',
|
|
13
12
|
setup: function (config, amplitude) {
|
|
14
13
|
var _a;
|
|
15
14
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;
|
|
1
|
+
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AAEpE,qCAA2G;AAGpG,IAAM,oBAAoB,GAA+B,UAAU,OAAqB;IAA/B,iBAuC/D;IAvCyE,wBAAA,EAAA,YAAqB;IAC7F,IAAM,MAAM,GAAiB;QAC3B,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,QAAQ;QAEd,KAAK,EAAE,UAAgB,MAAqB,EAAE,SAAwB;;;;;;;4BAC9D,YAAY,sBAChB,iBAAiB,EAAE,OAAO,EAC1B,yBAAyB,EAAE,KAAK,EAChC,gBAAgB,EAAE,IAAA,qCAA2B,EAAC,MAAA,MAAM,CAAC,aAAa,0CAAE,MAAM,CAAC,IACxE,OAAO,CACX,CAAC;4BACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;4BAG7E,OAAO,GAAG,MAAM,CAAC,aAA6C,CAAC;4BAC/D,UAAU,GAAG,IAAA,uBAAa,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;4BAEZ,qBAAM,OAAO,CAAC,GAAG,CAAC;oCAC5D,IAAI,wCAAc,EAAE,CAAC,KAAK,EAAE;oCAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;iCACxB,CAAC,EAAA;;4BAHI,KAAA,8BAAsC,SAG1C,KAAA,EAHK,eAAe,QAAA,EAAE,gBAAgB,QAAA;4BAKxC,IAAI,IAAA,uBAAa,EAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,CAAC,EAAE;gCAClE,IAAI,YAAY,CAAC,yBAAyB,EAAE;oCAC1C,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCACnC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;iCACtE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gCAC7C,aAAa,GAAG,IAAA,6BAAmB,EAAC,eAAe,EAAE,YAAY,CAAC,CAAC;gCACzE,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;gCAC/B,KAAK,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;6BAC/C;;;;;SACF;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAvCW,QAAA,oBAAoB,wBAuC/B","sourcesContent":["import { CampaignParser } from '@amplitude/analytics-client-common';\nimport { BeforePlugin, BrowserClient, BrowserConfig, Campaign, Event, Storage } from '@amplitude/analytics-types';\nimport { createCampaignEvent, getDefaultExcludedReferrers, getStorageKey, isNewCampaign } from './helpers';\nimport { CreateWebAttributionPlugin, Options } from './typings/web-attribution';\n\nexport const webAttributionPlugin: CreateWebAttributionPlugin = function (options: Options = {}) {\n const plugin: BeforePlugin = {\n name: '@amplitude/plugin-web-attribution-browser',\n type: 'before',\n\n setup: async function (config: BrowserConfig, amplitude: BrowserClient) {\n const pluginConfig = {\n initialEmptyValue: 'EMPTY',\n resetSessionOnNewCampaign: false,\n excludeReferrers: getDefaultExcludedReferrers(config.cookieOptions?.domain),\n ...options,\n };\n config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.');\n\n // Share cookie storage with user session storage\n const storage = config.cookieStorage as unknown as Storage<Campaign>;\n const storageKey = getStorageKey(config.apiKey, 'MKTG');\n\n const [currentCampaign, previousCampaign] = await Promise.all([\n new CampaignParser().parse(),\n storage.get(storageKey),\n ]);\n\n if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig)) {\n if (pluginConfig.resetSessionOnNewCampaign) {\n amplitude.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign.');\n }\n config.loggerProvider.log('Tracking attribution.');\n const campaignEvent = createCampaignEvent(currentCampaign, pluginConfig);\n amplitude.track(campaignEvent);\n void storage.set(storageKey, currentCampaign);\n }\n },\n\n execute: async (event: Event) => event,\n };\n\n return plugin;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAW,MAAM,2BAA2B,CAAC;AAEhF,eAAO,MAAM,oBAAoB,EAAE,0BAuClC,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator, __read } from "tslib";
|
|
2
2
|
import { CampaignParser } from '@amplitude/analytics-client-common';
|
|
3
|
-
import { PluginType, } from '@amplitude/analytics-types';
|
|
4
3
|
import { createCampaignEvent, getDefaultExcludedReferrers, getStorageKey, isNewCampaign } from './helpers';
|
|
5
4
|
export var webAttributionPlugin = function (options) {
|
|
6
5
|
var _this = this;
|
|
7
6
|
if (options === void 0) { options = {}; }
|
|
8
7
|
var plugin = {
|
|
9
8
|
name: '@amplitude/plugin-web-attribution-browser',
|
|
10
|
-
type:
|
|
9
|
+
type: 'before',
|
|
11
10
|
setup: function (config, amplitude) {
|
|
12
11
|
var _a;
|
|
13
12
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAG3G,MAAM,CAAC,IAAM,oBAAoB,GAA+B,UAAU,OAAqB;IAA/B,iBAuC/D;IAvCyE,wBAAA,EAAA,YAAqB;IAC7F,IAAM,MAAM,GAAiB;QAC3B,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,QAAQ;QAEd,KAAK,EAAE,UAAgB,MAAqB,EAAE,SAAwB;;;;;;;4BAC9D,YAAY,cAChB,iBAAiB,EAAE,OAAO,EAC1B,yBAAyB,EAAE,KAAK,EAChC,gBAAgB,EAAE,2BAA2B,CAAC,MAAA,MAAM,CAAC,aAAa,0CAAE,MAAM,CAAC,IACxE,OAAO,CACX,CAAC;4BACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;4BAG7E,OAAO,GAAG,MAAM,CAAC,aAA6C,CAAC;4BAC/D,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;4BAEZ,qBAAM,OAAO,CAAC,GAAG,CAAC;oCAC5D,IAAI,cAAc,EAAE,CAAC,KAAK,EAAE;oCAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;iCACxB,CAAC,EAAA;;4BAHI,KAAA,sBAAsC,SAG1C,KAAA,EAHK,eAAe,QAAA,EAAE,gBAAgB,QAAA;4BAKxC,IAAI,aAAa,CAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,CAAC,EAAE;gCAClE,IAAI,YAAY,CAAC,yBAAyB,EAAE;oCAC1C,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCACnC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;iCACtE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gCAC7C,aAAa,GAAG,mBAAmB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;gCACzE,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;gCAC/B,KAAK,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;6BAC/C;;;;;SACF;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { CampaignParser } from '@amplitude/analytics-client-common';\nimport { BeforePlugin, BrowserClient, BrowserConfig, Campaign, Event, Storage } from '@amplitude/analytics-types';\nimport { createCampaignEvent, getDefaultExcludedReferrers, getStorageKey, isNewCampaign } from './helpers';\nimport { CreateWebAttributionPlugin, Options } from './typings/web-attribution';\n\nexport const webAttributionPlugin: CreateWebAttributionPlugin = function (options: Options = {}) {\n const plugin: BeforePlugin = {\n name: '@amplitude/plugin-web-attribution-browser',\n type: 'before',\n\n setup: async function (config: BrowserConfig, amplitude: BrowserClient) {\n const pluginConfig = {\n initialEmptyValue: 'EMPTY',\n resetSessionOnNewCampaign: false,\n excludeReferrers: getDefaultExcludedReferrers(config.cookieOptions?.domain),\n ...options,\n };\n config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.');\n\n // Share cookie storage with user session storage\n const storage = config.cookieStorage as unknown as Storage<Campaign>;\n const storageKey = getStorageKey(config.apiKey, 'MKTG');\n\n const [currentCampaign, previousCampaign] = await Promise.all([\n new CampaignParser().parse(),\n storage.get(storageKey),\n ]);\n\n if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig)) {\n if (pluginConfig.resetSessionOnNewCampaign) {\n amplitude.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign.');\n }\n config.loggerProvider.log('Tracking attribution.');\n const campaignEvent = createCampaignEvent(currentCampaign, pluginConfig);\n amplitude.track(campaignEvent);\n void storage.set(storageKey, currentCampaign);\n }\n },\n\n execute: async (event: Event) => event,\n };\n\n return plugin;\n};\n"]}
|
|
@@ -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=function(){return t=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},t.apply(this,arguments)};function r(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 n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function u(e){try{f(n.next(e))}catch(e){o(e)}}function a(e){try{f(n.throw(e))}catch(e){o(e)}}function f(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}f((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(f){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,n=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,f])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)u.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 u}var u,a,f,s
|
|
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=function(){return t=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},t.apply(this,arguments)};function r(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 n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function u(e){try{f(n.next(e))}catch(e){o(e)}}function a(e){try{f(n.throw(e))}catch(e){o(e)}}function f(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}f((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(f){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,n=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,f])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)u.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 u}var u,a,f,s=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=l(r[0]),i=l(r[1]);return i?(e[n]=i,e):e}),{}):{}},l=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},c="dclid",d="fbclid",p="gbraid",v="gclid",y="ko_click_id",h="li_fat_id",_="msclkid",m="rtd_cid",g="ttclid",b="twclid",E="wbraid",S={utm_campaign:void 0,utm_content:void 0,utm_id:void 0,utm_medium:void 0,utm_source:void 0,utm_term: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,li_fat_id:void 0,msclkid:void 0,rtd_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},w=function(){function e(){}return e.prototype.parse=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,t(t(t(t({},S),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=s();return{utm_campaign:e.utm_campaign,utm_content:e.utm_content,utm_id:e.utm_id,utm_medium:e.utm_medium,utm_source:e.utm_source,utm_term:e.utm_term}},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=s();return(e={})[c]=t[c],e[d]=t[d],e[p]=t[p],e[v]=t[v],e[y]=t[y],e[h]=t[h],e[_]=t[_],e[m]=t[m],e[g]=t[g],e[b]=t[b],e[E]=t[E],e},e}();!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"}(u||(u={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(a||(a={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(f||(f={}));var O="AMP",P=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!T(t,r))return!1}return!0},T=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),u=o.next();!u.done;u=o.next()){var a=u.value;if(Array.isArray(a))return!1;if("object"==typeof a)i=i&&P(a);else if(!["number","string"].includes(typeof a))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return P(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},R=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return t({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(u.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(u.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(u.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(u.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(u.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(u.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(u.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(u.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(u.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[u.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,t,r){return void 0===this._properties[u.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===u.ADD?"number"==typeof r:e===u.UNSET||e===u.REMOVE||T(t,r)))},e}(),N=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},I=function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=""),e.some((function(e){return e instanceof RegExp?e.test(t):e===t}))},A=function(e,r){var n,i,u=t(t({},S),e),a=Object.entries(u).reduce((function(e,t){var n,i=o(t,2),u=i[0],a=i[1];return e.setOnce("initial_".concat(u),null!==(n=null!=a?a:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),a?e.set(u,a):e.unset(u)}),new R);return n=a,t(t({},i),{event_type:f.IDENTIFY,user_properties:n.getUserProperties()})},x=function(e){var u=this;void 0===e&&(e={});var a={name:"@amplitude/plugin-web-attribution-browser",type:"before",setup:function(u,a){var f;return n(this,void 0,void 0,(function(){var n,s,l,c,d,p,v;return i(this,(function(i){switch(i.label){case 0:return n=t({initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1,excludeReferrers:(m=null===(f=u.cookieOptions)||void 0===f?void 0:f.domain,g=m,g?(g.startsWith(".")&&(g=g.substring(1)),[new RegExp("".concat(g.replace(".","\\."),"$"))]):[])},e),u.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser."),s=u.cookieStorage,y=u.apiKey,void 0===(h="MKTG")&&(h=""),void 0===_&&(_=10),l=[O,h,y.substring(0,_)].filter(Boolean).join("_"),[4,Promise.all([(new w).parse(),s.get(l)])];case 1:return c=o.apply(void 0,[i.sent(),2]),d=c[0],p=c[1],function(e,t,n){e.referrer;var i=e.referring_domain,o=r(e,["referrer","referring_domain"]),u=t||{};u.referrer;var a=u.referring_domain,f=r(u,["referrer","referring_domain"]);if(I(n.excludeReferrers,e.referring_domain))return!1;var s=JSON.stringify(o)!==JSON.stringify(f),l=N(i||"")!==N(a||"");return!t||s||l}(d,p,n)&&(n.resetSessionOnNewCampaign&&(a.setSessionId(Date.now()),u.loggerProvider.log("Created a new session for new campaign.")),u.loggerProvider.log("Tracking attribution."),v=A(d,n),a.track(v),s.set(l,d)),[2]}var y,h,_,m,g}))}))},execute:function(e){return n(u,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))}};return a},$=Object.freeze({__proto__:null});e.Types=$,e.plugin=x,e.webAttributionPlugin=x,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAW,MAAM,2BAA2B,CAAC;AAEhF,eAAO,MAAM,oBAAoB,EAAE,0BAuClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/plugin-web-attribution-browser",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
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": "^2.0.0-beta.
|
|
40
|
-
"@amplitude/analytics-types": "^2.0.0-beta.
|
|
39
|
+
"@amplitude/analytics-client-common": "^2.0.0-beta.2",
|
|
40
|
+
"@amplitude/analytics-types": "^2.0.0-beta.2",
|
|
41
41
|
"tslib": "^2.4.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@amplitude/analytics-browser": "^2.0.0-beta.
|
|
44
|
+
"@amplitude/analytics-browser": "^2.0.0-beta.2",
|
|
45
45
|
"@rollup/plugin-commonjs": "^23.0.4",
|
|
46
46
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
47
47
|
"@rollup/plugin-typescript": "^10.0.1",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"files": [
|
|
54
54
|
"lib"
|
|
55
55
|
],
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "90d499213d9c011e853e85f83d543d878cd72b13"
|
|
57
57
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var webAttribution=function(e){"use strict";var t=function(){return t=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},t.apply(this,arguments)};function r(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 n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function u(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}c((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,n=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)u.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 u}var u,a,c,s,f=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=l(r[0]),i=l(r[1]);return i?(e[n]=i,e):e}),{}):{}},l=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},d="dclid",p="fbclid",v="gbraid",y="gclid",h="ko_click_id",_="li_fat_id",m="msclkid",g="rtd_cid",E="ttclid",b="twclid",S="wbraid",w={utm_campaign:void 0,utm_content:void 0,utm_id:void 0,utm_medium:void 0,utm_source:void 0,utm_term: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,li_fat_id:void 0,msclkid:void 0,rtd_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},O=function(){function e(){}return e.prototype.parse=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,t(t(t(t({},w),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=f();return{utm_campaign:e.utm_campaign,utm_content:e.utm_content,utm_id:e.utm_id,utm_medium:e.utm_medium,utm_source:e.utm_source,utm_term:e.utm_term}},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=f();return(e={})[d]=t[d],e[p]=t[p],e[v]=t[v],e[y]=t[y],e[h]=t[h],e[_]=t[_],e[m]=t[m],e[g]=t[g],e[E]=t[E],e[b]=t[b],e[S]=t[S],e},e}();!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"}(u||(u={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(a||(a={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(c||(c={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(s||(s={}));var P="AMP",R=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!T(t,r))return!1}return!0},T=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),u=o.next();!u.done;u=o.next()){var a=u.value;if(Array.isArray(a))return!1;if("object"==typeof a)i=i&&R(a);else if(!["number","string"].includes(typeof a))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return R(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},N=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return t({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(u.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(u.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(u.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(u.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(u.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(u.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(u.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(u.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(u.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[u.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,t,r){return void 0===this._properties[u.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===u.ADD?"number"==typeof r:e===u.UNSET||e===u.REMOVE||T(t,r)))},e}(),I=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},A=function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=""),e.some((function(e){return e instanceof RegExp?e.test(t):e===t}))},$=function(e,r){var n,i,u=t(t({},w),e),a=Object.entries(u).reduce((function(e,t){var n,i=o(t,2),u=i[0],a=i[1];return e.setOnce("initial_".concat(u),null!==(n=null!=a?a:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),a?e.set(u,a):e.unset(u)}),new N);return n=a,t(t({},i),{event_type:c.IDENTIFY,user_properties:n.getUserProperties()})},k=function(e){var u=this;void 0===e&&(e={});var a={name:"@amplitude/plugin-web-attribution-browser",type:s.BEFORE,setup:function(u,a){var c;return n(this,void 0,void 0,(function(){var n,s,f,l,d,p,v;return i(this,(function(i){switch(i.label){case 0:return n=t({initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1,excludeReferrers:(m=null===(c=u.cookieOptions)||void 0===c?void 0:c.domain,g=m,g?(g.startsWith(".")&&(g=g.substring(1)),[new RegExp("".concat(g.replace(".","\\."),"$"))]):[])},e),u.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser."),s=u.cookieStorage,y=u.apiKey,void 0===(h="MKTG")&&(h=""),void 0===_&&(_=10),f=[P,h,y.substring(0,_)].filter(Boolean).join("_"),[4,Promise.all([(new O).parse(),s.get(f)])];case 1:return l=o.apply(void 0,[i.sent(),2]),d=l[0],p=l[1],function(e,t,n){e.referrer;var i=e.referring_domain,o=r(e,["referrer","referring_domain"]),u=t||{};u.referrer;var a=u.referring_domain,c=r(u,["referrer","referring_domain"]);if(A(n.excludeReferrers,e.referring_domain))return!1;var s=JSON.stringify(o)!==JSON.stringify(c),f=I(i||"")!==I(a||"");return!t||s||f}(d,p,n)&&(n.resetSessionOnNewCampaign&&(a.setSessionId(Date.now()),u.loggerProvider.log("Created a new session for new campaign.")),u.loggerProvider.log("Tracking attribution."),v=$(d,n),a.track(v),s.set(f,d)),[2]}var y,h,_,m,g}))}))},execute:function(e){return n(u,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))}};return a},D=Object.freeze({__proto__:null});return e.Types=D,e.plugin=k,e.webAttributionPlugin=k,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
|
Binary file
|