@amplitude/analytics-react-native 0.3.3 → 0.4.0

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.
Files changed (116) hide show
  1. package/lib/commonjs/config.js +10 -18
  2. package/lib/commonjs/config.js.map +1 -1
  3. package/lib/commonjs/cookie-migration/index.js +3 -5
  4. package/lib/commonjs/cookie-migration/index.js.map +1 -1
  5. package/lib/commonjs/plugins/context.js +8 -2
  6. package/lib/commonjs/plugins/context.js.map +1 -1
  7. package/lib/commonjs/react-native-client.js +7 -11
  8. package/lib/commonjs/react-native-client.js.map +1 -1
  9. package/lib/commonjs/version.js +1 -1
  10. package/lib/commonjs/version.js.map +1 -1
  11. package/lib/module/config.js +1 -5
  12. package/lib/module/config.js.map +1 -1
  13. package/lib/module/cookie-migration/index.js +1 -2
  14. package/lib/module/cookie-migration/index.js.map +1 -1
  15. package/lib/module/plugins/context.js +7 -1
  16. package/lib/module/plugins/context.js.map +1 -1
  17. package/lib/module/react-native-client.js +1 -3
  18. package/lib/module/react-native-client.js.map +1 -1
  19. package/lib/module/version.js +1 -1
  20. package/lib/module/version.js.map +1 -1
  21. package/lib/typescript/config.d.ts +1 -2
  22. package/lib/typescript/config.d.ts.map +1 -1
  23. package/lib/typescript/cookie-migration/index.d.ts.map +1 -1
  24. package/lib/typescript/plugins/context.d.ts.map +1 -1
  25. package/lib/typescript/react-native-client.d.ts.map +1 -1
  26. package/lib/typescript/version.d.ts +1 -1
  27. package/package.json +5 -4
  28. package/src/config.ts +7 -5
  29. package/src/cookie-migration/index.ts +1 -2
  30. package/src/plugins/context.ts +7 -1
  31. package/src/react-native-client.ts +1 -3
  32. package/src/version.ts +1 -1
  33. package/lib/commonjs/attribution/campaign-parser.js +0 -74
  34. package/lib/commonjs/attribution/campaign-parser.js.map +0 -1
  35. package/lib/commonjs/attribution/campaign-tracker.js +0 -133
  36. package/lib/commonjs/attribution/campaign-tracker.js.map +0 -1
  37. package/lib/commonjs/attribution/constants.js +0 -47
  38. package/lib/commonjs/attribution/constants.js.map +0 -1
  39. package/lib/commonjs/plugins/identity.js +0 -40
  40. package/lib/commonjs/plugins/identity.js.map +0 -1
  41. package/lib/commonjs/session-manager.js +0 -114
  42. package/lib/commonjs/session-manager.js.map +0 -1
  43. package/lib/commonjs/storage/cookie.js +0 -124
  44. package/lib/commonjs/storage/cookie.js.map +0 -1
  45. package/lib/commonjs/storage/utm-cookie.js +0 -42
  46. package/lib/commonjs/storage/utm-cookie.js.map +0 -1
  47. package/lib/commonjs/transports/fetch.js +0 -34
  48. package/lib/commonjs/transports/fetch.js.map +0 -1
  49. package/lib/commonjs/utils/analytics-connector.js +0 -15
  50. package/lib/commonjs/utils/analytics-connector.js.map +0 -1
  51. package/lib/commonjs/utils/cookie-name.js +0 -23
  52. package/lib/commonjs/utils/cookie-name.js.map +0 -1
  53. package/lib/commonjs/utils/language.js +0 -18
  54. package/lib/commonjs/utils/language.js.map +0 -1
  55. package/lib/commonjs/utils/query-params.js +0 -43
  56. package/lib/commonjs/utils/query-params.js.map +0 -1
  57. package/lib/module/attribution/campaign-parser.js +0 -62
  58. package/lib/module/attribution/campaign-parser.js.map +0 -1
  59. package/lib/module/attribution/campaign-tracker.js +0 -120
  60. package/lib/module/attribution/campaign-tracker.js.map +0 -1
  61. package/lib/module/attribution/constants.js +0 -26
  62. package/lib/module/attribution/constants.js.map +0 -1
  63. package/lib/module/plugins/identity.js +0 -29
  64. package/lib/module/plugins/identity.js.map +0 -1
  65. package/lib/module/session-manager.js +0 -104
  66. package/lib/module/session-manager.js.map +0 -1
  67. package/lib/module/storage/cookie.js +0 -114
  68. package/lib/module/storage/cookie.js.map +0 -1
  69. package/lib/module/storage/utm-cookie.js +0 -32
  70. package/lib/module/storage/utm-cookie.js.map +0 -1
  71. package/lib/module/transports/fetch.js +0 -24
  72. package/lib/module/transports/fetch.js.map +0 -1
  73. package/lib/module/utils/analytics-connector.js +0 -5
  74. package/lib/module/utils/analytics-connector.js.map +0 -1
  75. package/lib/module/utils/cookie-name.js +0 -10
  76. package/lib/module/utils/cookie-name.js.map +0 -1
  77. package/lib/module/utils/language.js +0 -9
  78. package/lib/module/utils/language.js.map +0 -1
  79. package/lib/module/utils/query-params.js +0 -31
  80. package/lib/module/utils/query-params.js.map +0 -1
  81. package/lib/typescript/attribution/campaign-parser.d.ts +0 -10
  82. package/lib/typescript/attribution/campaign-parser.d.ts.map +0 -1
  83. package/lib/typescript/attribution/campaign-tracker.d.ts +0 -74
  84. package/lib/typescript/attribution/campaign-tracker.d.ts.map +0 -1
  85. package/lib/typescript/attribution/constants.d.ts +0 -17
  86. package/lib/typescript/attribution/constants.d.ts.map +0 -1
  87. package/lib/typescript/plugins/identity.d.ts +0 -9
  88. package/lib/typescript/plugins/identity.d.ts.map +0 -1
  89. package/lib/typescript/session-manager.d.ts +0 -28
  90. package/lib/typescript/session-manager.d.ts.map +0 -1
  91. package/lib/typescript/storage/cookie.d.ts +0 -12
  92. package/lib/typescript/storage/cookie.d.ts.map +0 -1
  93. package/lib/typescript/storage/utm-cookie.d.ts +0 -6
  94. package/lib/typescript/storage/utm-cookie.d.ts.map +0 -1
  95. package/lib/typescript/transports/fetch.d.ts +0 -6
  96. package/lib/typescript/transports/fetch.d.ts.map +0 -1
  97. package/lib/typescript/utils/analytics-connector.d.ts +0 -3
  98. package/lib/typescript/utils/analytics-connector.d.ts.map +0 -1
  99. package/lib/typescript/utils/cookie-name.d.ts +0 -3
  100. package/lib/typescript/utils/cookie-name.d.ts.map +0 -1
  101. package/lib/typescript/utils/language.d.ts +0 -2
  102. package/lib/typescript/utils/language.d.ts.map +0 -1
  103. package/lib/typescript/utils/query-params.d.ts +0 -3
  104. package/lib/typescript/utils/query-params.d.ts.map +0 -1
  105. package/src/attribution/campaign-parser.ts +0 -78
  106. package/src/attribution/campaign-tracker.ts +0 -112
  107. package/src/attribution/constants.ts +0 -32
  108. package/src/plugins/identity.ts +0 -21
  109. package/src/session-manager.ts +0 -81
  110. package/src/storage/cookie.ts +0 -97
  111. package/src/storage/utm-cookie.ts +0 -27
  112. package/src/transports/fetch.ts +0 -23
  113. package/src/utils/analytics-connector.ts +0 -5
  114. package/src/utils/cookie-name.ts +0 -9
  115. package/src/utils/language.ts +0 -7
  116. package/src/utils/query-params.ts +0 -26
@@ -1,74 +0,0 @@
1
- import { Storage, Campaign, CampaignParser as ICampaignParser, CampaignTracker as ICampaignTracker, CampaignTrackFunction, CampaignTrackerOptions } from '@amplitude/analytics-types';
2
- export declare class CampaignTracker implements ICampaignTracker {
3
- storage: Storage<Campaign>;
4
- storageKey: string;
5
- parser: ICampaignParser;
6
- track: CampaignTrackFunction;
7
- onNewCampaign: (campaign: Campaign) => unknown;
8
- disabled: boolean;
9
- trackNewCampaigns: boolean;
10
- trackPageViews: boolean;
11
- excludeReferrers: string[];
12
- initialEmptyValue: string;
13
- constructor(apiKey: string, options: CampaignTrackerOptions);
14
- isNewCampaign(currentCampaign: Campaign, previousCampaign: Campaign): boolean;
15
- saveCampaignToStorage(campaign: Campaign): Promise<void>;
16
- getCampaignFromStorage(): Promise<Campaign>;
17
- createCampaignEvent(campaign: Campaign): {
18
- event_type: string;
19
- event_properties?: {
20
- [key: string]: any;
21
- } | undefined;
22
- user_properties: {
23
- [key: string]: any;
24
- } | import("@amplitude/analytics-types").IdentifyUserProperties | {
25
- [x: string]: any;
26
- };
27
- group_properties?: {
28
- [key: string]: any;
29
- } | undefined;
30
- groups?: {
31
- [key: string]: any;
32
- } | undefined;
33
- user_id?: string | undefined;
34
- device_id?: string | undefined;
35
- time?: number | undefined;
36
- location_lat?: number | undefined;
37
- location_lng?: number | undefined;
38
- app_version?: string | undefined;
39
- version_name?: string | undefined;
40
- library?: string | undefined;
41
- platform?: string | undefined;
42
- os_name?: string | undefined;
43
- os_version?: string | undefined;
44
- device_brand?: string | undefined;
45
- device_manufacturer?: string | undefined;
46
- device_model?: string | undefined;
47
- carrier?: string | undefined;
48
- country?: string | undefined;
49
- region?: string | undefined;
50
- city?: string | undefined;
51
- dma?: string | undefined;
52
- idfa?: string | undefined;
53
- idfv?: string | undefined;
54
- adid?: string | undefined;
55
- android_id?: string | undefined;
56
- language?: string | undefined;
57
- ip?: string | undefined;
58
- price?: number | undefined;
59
- quantity?: number | undefined;
60
- revenue?: number | undefined;
61
- productId?: string | undefined;
62
- revenueType?: string | undefined;
63
- event_id?: number | undefined;
64
- session_id?: number | undefined;
65
- insert_id?: string | undefined;
66
- plan?: import("@amplitude/analytics-types").Plan | undefined;
67
- partner_id?: string | undefined;
68
- extra?: {
69
- [key: string]: any;
70
- } | undefined;
71
- };
72
- send(isNewSession: boolean): Promise<void>;
73
- }
74
- //# sourceMappingURL=campaign-tracker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"campaign-tracker.d.ts","sourceRoot":"","sources":["../../../src/attribution/campaign-tracker.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,cAAc,IAAI,eAAe,EACjC,eAAe,IAAI,gBAAgB,EACnC,qBAAqB,EACrB,sBAAsB,EAEvB,MAAM,4BAA4B,CAAC;AAKpC,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,qBAAqB,CAAC;IAC7B,aAAa,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC;IAE/C,QAAQ,EAAE,OAAO,CAAC;IAClB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;gBAEd,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB;IAiB3D,aAAa,CAAC,eAAe,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ;IAe7D,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD,sBAAsB,IAAI,OAAO,CAAC,QAAQ,CAAC;IAIjD,mBAAmB,CAAC,QAAQ,EAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6BhC,IAAI,CAAC,YAAY,EAAE,OAAO;CAejC"}
@@ -1,17 +0,0 @@
1
- import { Campaign } from '@amplitude/analytics-types';
2
- export declare const UTM_SOURCE = "utm_source";
3
- export declare const UTM_MEDIUM = "utm_medium";
4
- export declare const UTM_CAMPAIGN = "utm_campaign";
5
- export declare const UTM_TERM = "utm_term";
6
- export declare const UTM_CONTENT = "utm_content";
7
- export declare const UTMZ_SOURCE = "utmcsr";
8
- export declare const UTMZ_MEDIUM = "utmcmd";
9
- export declare const UTMZ_CAMPAIGN = "utmccn";
10
- export declare const UTMZ_TERM = "utmctr";
11
- export declare const UTMZ_CONTENT = "utmcct";
12
- export declare const GCLID = "gclid";
13
- export declare const FBCLID = "fbclid";
14
- export declare const EMPTY_VALUE = "EMPTY";
15
- export declare const BASE_CAMPAIGN: Campaign;
16
- export declare const MKTG = "MKTG";
17
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/attribution/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAC3C,eAAO,MAAM,QAAQ,aAAa,CAAC;AACnC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,eAAO,MAAM,WAAW,WAAW,CAAC;AACpC,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,eAAO,MAAM,KAAK,UAAU,CAAC;AAC7B,eAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,eAAO,MAAM,aAAa,EAAE,QAU3B,CAAC;AAEF,eAAO,MAAM,IAAI,SAAS,CAAC"}
@@ -1,9 +0,0 @@
1
- import { BeforePlugin, PluginType, Event, Config } from '@amplitude/analytics-types';
2
- export declare class IdentityEventSender implements BeforePlugin {
3
- name: string;
4
- type: PluginType.BEFORE;
5
- identityStore: import("@amplitude/analytics-connector/dist/types/src/identityStore").IdentityStoreImpl;
6
- execute(context: Event): Promise<Event>;
7
- setup(_: Config): Promise<undefined>;
8
- }
9
- //# sourceMappingURL=identity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../../src/plugins/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGrF,qBAAa,mBAAoB,YAAW,YAAY;IACtD,IAAI,SAAc;IAClB,IAAI,oBAA8B;IAElC,aAAa,0FAAyC;IAEhD,OAAO,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAQ7C,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAGrC"}
@@ -1,28 +0,0 @@
1
- import { UserSession, Storage, SessionManager as ISessionManager } from '@amplitude/analytics-types';
2
- export declare class SessionManager implements ISessionManager {
3
- private storage;
4
- storageKey: string;
5
- cache: UserSession;
6
- isSessionCacheValid: boolean;
7
- constructor(storage: Storage<UserSession>, apiKey: string);
8
- /**
9
- * load() must be called immediately after instantation
10
- *
11
- * ```ts
12
- * await new SessionManager(...).load();
13
- * ```
14
- */
15
- load(): Promise<this>;
16
- setSession(session: Partial<UserSession>): void;
17
- getSessionId(): number | undefined;
18
- setSessionId(sessionId: number): void;
19
- getDeviceId(): string | undefined;
20
- setDeviceId(deviceId: string): void;
21
- getUserId(): string | undefined;
22
- setUserId(userId: string): void;
23
- getLastEventTime(): number | undefined;
24
- setLastEventTime(lastEventTime: number): void;
25
- getOptOut(): boolean;
26
- setOptOut(optOut: boolean): void;
27
- }
28
- //# sourceMappingURL=session-manager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src/session-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGrG,qBAAa,cAAe,YAAW,eAAe;IAKxC,OAAO,CAAC,OAAO;IAJ3B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,mBAAmB,UAAQ;gBAEP,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM;IAKjE;;;;;;OAMG;IACG,IAAI;IAOV,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC;IAKxC,YAAY;IAWZ,YAAY,CAAC,SAAS,EAAE,MAAM;IAM9B,WAAW,IAAI,MAAM,GAAG,SAAS;IAIjC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAInC,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/B,gBAAgB;IAIhB,gBAAgB,CAAC,aAAa,EAAE,MAAM;IAItC,SAAS,IAAI,OAAO;IAIpB,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;CAGjC"}
@@ -1,12 +0,0 @@
1
- import { Storage, CookieStorageOptions } from '@amplitude/analytics-types';
2
- export declare class CookieStorage<T> implements Storage<T> {
3
- options: CookieStorageOptions;
4
- constructor(options?: CookieStorageOptions);
5
- isEnabled(): Promise<boolean>;
6
- get(key: string): Promise<T | undefined>;
7
- getRaw(key: string): Promise<string | undefined>;
8
- set(key: string, value: T | null): Promise<void>;
9
- remove(key: string): Promise<void>;
10
- reset(): Promise<void>;
11
- }
12
- //# sourceMappingURL=cookie.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAG3E,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,EAAE,oBAAoB,CAAC;gBAElB,OAAO,CAAC,EAAE,oBAAoB;IAIpC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAqB7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAmBxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAShD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BhD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
@@ -1,6 +0,0 @@
1
- import { CookieStorage } from './cookie';
2
- export declare class UTMCookie extends CookieStorage<Record<string, string | undefined>> {
3
- get(key: string): Promise<Record<string, string | undefined> | undefined>;
4
- set(): Promise<void>;
5
- }
6
- //# sourceMappingURL=utm-cookie.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utm-cookie.d.ts","sourceRoot":"","sources":["../../../src/storage/utm-cookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,qBAAa,SAAU,SAAQ,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC;IAoBzE,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAG3B"}
@@ -1,6 +0,0 @@
1
- import { BaseTransport } from '@amplitude/analytics-core';
2
- import { Payload, Response, Transport } from '@amplitude/analytics-types';
3
- export declare class FetchTransport extends BaseTransport implements Transport {
4
- send(serverUrl: string, payload: Payload): Promise<Response | null>;
5
- }
6
- //# sourceMappingURL=fetch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE1E,qBAAa,cAAe,SAAQ,aAAc,YAAW,SAAS;IAC9D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAkB1E"}
@@ -1,3 +0,0 @@
1
- import { AnalyticsConnector } from '@amplitude/analytics-connector';
2
- export declare const getAnalyticsConnector: () => AnalyticsConnector;
3
- //# sourceMappingURL=analytics-connector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analytics-connector.d.ts","sourceRoot":"","sources":["../../../src/utils/analytics-connector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,eAAO,MAAM,qBAAqB,QAAO,kBAExC,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const getCookieName: (apiKey: string, postKey?: string, limit?: number) => string;
2
- export declare const getOldCookieName: (apiKey: string) => string;
3
- //# sourceMappingURL=cookie-name.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cookie-name.d.ts","sourceRoot":"","sources":["../../../src/utils/cookie-name.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,WAAY,MAAM,6CAE3C,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAAY,MAAM,WAE9C,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const getLanguage: () => string;
2
- //# sourceMappingURL=language.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../../../src/utils/language.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAO,MAM9B,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const getQueryParams: () => Record<string, string | undefined>;
2
- export declare const tryDecodeURIComponent: (value?: string) => string;
3
- //# sourceMappingURL=query-params.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/utils/query-params.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,QAAO,OAAO,MAAM,EAAE,MAAM,GAAG,SAAS,CAiBlE,CAAC;AAEF,eAAO,MAAM,qBAAqB,4BAMjC,CAAC"}
@@ -1,78 +0,0 @@
1
- import { UTMCookie } from '../storage/utm-cookie';
2
- import { getQueryParams } from '../utils/query-params';
3
- import {
4
- UTM_CAMPAIGN,
5
- UTM_CONTENT,
6
- UTM_MEDIUM,
7
- UTM_SOURCE,
8
- UTM_TERM,
9
- UTMZ_SOURCE,
10
- UTMZ_MEDIUM,
11
- UTMZ_CAMPAIGN,
12
- UTMZ_TERM,
13
- UTMZ_CONTENT,
14
- GCLID,
15
- FBCLID,
16
- BASE_CAMPAIGN,
17
- } from './constants';
18
- import {
19
- Campaign,
20
- CampaignParser as ICampaignParser,
21
- ClickIdParameters,
22
- ReferrerParameters,
23
- UTMParameters,
24
- } from '@amplitude/analytics-types';
25
-
26
- export class CampaignParser implements ICampaignParser {
27
- utmCookieStorage = new UTMCookie();
28
-
29
- async parse(): Promise<Campaign> {
30
- return {
31
- ...BASE_CAMPAIGN,
32
- ...(await this.getUtmParam()),
33
- ...this.getReferrer(),
34
- ...this.getClickIds(),
35
- } as Campaign;
36
- }
37
-
38
- async getUtmParam(): Promise<UTMParameters> {
39
- const params = getQueryParams();
40
- const cookies = ((await this.utmCookieStorage.isEnabled()) && (await this.utmCookieStorage.get('__utmz'))) || {};
41
-
42
- const utmSource = params[UTM_SOURCE] || cookies[UTMZ_SOURCE];
43
- const utmMedium = params[UTM_MEDIUM] || cookies[UTMZ_MEDIUM];
44
- const utmCampaign = params[UTM_CAMPAIGN] || cookies[UTMZ_CAMPAIGN];
45
- const utmTerm = params[UTM_TERM] || cookies[UTMZ_TERM];
46
- const utmContent = params[UTM_CONTENT] || cookies[UTMZ_CONTENT];
47
-
48
- return {
49
- utm_source: utmSource,
50
- utm_medium: utmMedium,
51
- utm_campaign: utmCampaign,
52
- utm_term: utmTerm,
53
- utm_content: utmContent,
54
- };
55
- }
56
-
57
- getReferrer(): ReferrerParameters {
58
- const data: ReferrerParameters = {
59
- referrer: undefined,
60
- referring_domain: undefined,
61
- };
62
- try {
63
- data.referrer = document.referrer || undefined;
64
- data.referring_domain = data.referrer?.split('/')[2] ?? undefined;
65
- } catch {
66
- // nothing to track
67
- }
68
- return data;
69
- }
70
-
71
- getClickIds(): ClickIdParameters {
72
- const params = getQueryParams();
73
- return {
74
- [GCLID]: params[GCLID],
75
- [FBCLID]: params[FBCLID],
76
- };
77
- }
78
- }
@@ -1,112 +0,0 @@
1
- import { createIdentifyEvent, Identify } from '@amplitude/analytics-core';
2
- import {
3
- Storage,
4
- Campaign,
5
- CampaignParser as ICampaignParser,
6
- CampaignTracker as ICampaignTracker,
7
- CampaignTrackFunction,
8
- CampaignTrackerOptions,
9
- BaseEvent,
10
- } from '@amplitude/analytics-types';
11
- import { getCookieName as getStorageKey } from '../utils/cookie-name';
12
- import { CampaignParser } from './campaign-parser';
13
- import { BASE_CAMPAIGN, EMPTY_VALUE, MKTG } from './constants';
14
-
15
- export class CampaignTracker implements ICampaignTracker {
16
- storage: Storage<Campaign>;
17
- storageKey: string;
18
- parser: ICampaignParser;
19
- track: CampaignTrackFunction;
20
- onNewCampaign: (campaign: Campaign) => unknown;
21
-
22
- disabled: boolean;
23
- trackNewCampaigns: boolean;
24
- trackPageViews: boolean;
25
- excludeReferrers: string[];
26
- initialEmptyValue: string;
27
-
28
- constructor(apiKey: string, options: CampaignTrackerOptions) {
29
- this.storage = options.storage;
30
- this.storageKey = getStorageKey(apiKey, MKTG);
31
- this.parser = new CampaignParser();
32
- this.track = options.track;
33
- this.onNewCampaign = options.onNewCampaign;
34
-
35
- this.disabled = Boolean(options.disabled);
36
- this.trackNewCampaigns = Boolean(options.trackNewCampaigns);
37
- this.trackPageViews = Boolean(options.trackPageViews);
38
- this.excludeReferrers = options.excludeReferrers ?? [];
39
- if (typeof location !== 'undefined') {
40
- this.excludeReferrers.unshift(location.hostname);
41
- }
42
- this.initialEmptyValue = options.initialEmptyValue ?? EMPTY_VALUE;
43
- }
44
-
45
- isNewCampaign(currentCampaign: Campaign, previousCampaign: Campaign) {
46
- const isReferrerExcluded = Boolean(
47
- currentCampaign.referring_domain && this.excludeReferrers.includes(currentCampaign.referring_domain),
48
- );
49
- const hasNewUtm =
50
- previousCampaign.utm_campaign !== currentCampaign.utm_campaign ||
51
- previousCampaign.utm_source !== currentCampaign.utm_source ||
52
- previousCampaign.utm_medium !== currentCampaign.utm_medium ||
53
- previousCampaign.utm_term !== currentCampaign.utm_term ||
54
- previousCampaign.utm_content !== currentCampaign.utm_content;
55
- const hasNewReferrer = previousCampaign.referring_domain !== currentCampaign.referring_domain;
56
-
57
- return !isReferrerExcluded && (hasNewUtm || hasNewReferrer);
58
- }
59
-
60
- async saveCampaignToStorage(campaign: Campaign): Promise<void> {
61
- await this.storage.set(this.storageKey, campaign);
62
- }
63
-
64
- async getCampaignFromStorage(): Promise<Campaign> {
65
- return (await this.storage.get(this.storageKey)) || { ...BASE_CAMPAIGN };
66
- }
67
-
68
- createCampaignEvent(campaign: Campaign) {
69
- const campaignParameters: Campaign = {
70
- // This object definition allows undefined keys to be iterated on
71
- // in .reduce() to build indentify object
72
- ...BASE_CAMPAIGN,
73
- ...campaign,
74
- };
75
- const identifyEvent = Object.entries(campaignParameters).reduce((identify, [key, value]) => {
76
- identify.setOnce(`initial_${key}`, value || this.initialEmptyValue);
77
- if (value) {
78
- return identify.set(key, value);
79
- }
80
- return identify.unset(key);
81
- }, new Identify());
82
-
83
- const pageViewEvent: BaseEvent = {
84
- event_type: 'Page View',
85
- event_properties: {
86
- page_title: /* istanbul ignore next */ (typeof document !== 'undefined' && document.title) || '',
87
- page_location: /* istanbul ignore next */ (typeof location !== 'undefined' && location.href) || '',
88
- page_path: /* istanbul ignore next */ (typeof location !== 'undefined' && location.pathname) || '',
89
- },
90
- };
91
- return {
92
- ...createIdentifyEvent(identifyEvent),
93
- ...(this.trackPageViews && pageViewEvent),
94
- };
95
- }
96
-
97
- async send(isNewSession: boolean) {
98
- if (this.disabled) {
99
- return;
100
- }
101
- const currentCampaign = await this.parser.parse();
102
- const previousCampaign = await this.getCampaignFromStorage();
103
- if (!isNewSession) {
104
- if (!this.trackNewCampaigns || !this.isNewCampaign(currentCampaign, previousCampaign)) {
105
- return;
106
- }
107
- this.onNewCampaign(currentCampaign);
108
- }
109
- await this.track(this.createCampaignEvent(currentCampaign));
110
- await this.saveCampaignToStorage(currentCampaign);
111
- }
112
- }
@@ -1,32 +0,0 @@
1
- import { Campaign } from '@amplitude/analytics-types';
2
-
3
- export const UTM_SOURCE = 'utm_source';
4
- export const UTM_MEDIUM = 'utm_medium';
5
- export const UTM_CAMPAIGN = 'utm_campaign';
6
- export const UTM_TERM = 'utm_term';
7
- export const UTM_CONTENT = 'utm_content';
8
-
9
- export const UTMZ_SOURCE = 'utmcsr';
10
- export const UTMZ_MEDIUM = 'utmcmd';
11
- export const UTMZ_CAMPAIGN = 'utmccn';
12
- export const UTMZ_TERM = 'utmctr';
13
- export const UTMZ_CONTENT = 'utmcct';
14
-
15
- export const GCLID = 'gclid';
16
- export const FBCLID = 'fbclid';
17
-
18
- export const EMPTY_VALUE = 'EMPTY';
19
-
20
- export const BASE_CAMPAIGN: Campaign = {
21
- utm_source: undefined,
22
- utm_medium: undefined,
23
- utm_campaign: undefined,
24
- utm_term: undefined,
25
- utm_content: undefined,
26
- referrer: undefined,
27
- referring_domain: undefined,
28
- gclid: undefined,
29
- fbclid: undefined,
30
- };
31
-
32
- export const MKTG = 'MKTG';
@@ -1,21 +0,0 @@
1
- import { BeforePlugin, PluginType, Event, Config } from '@amplitude/analytics-types';
2
- import { getAnalyticsConnector } from '../utils/analytics-connector';
3
-
4
- export class IdentityEventSender implements BeforePlugin {
5
- name = 'identity';
6
- type = PluginType.BEFORE as const;
7
-
8
- identityStore = getAnalyticsConnector().identityStore;
9
-
10
- async execute(context: Event): Promise<Event> {
11
- const userProperties = context.user_properties as Record<string, any>;
12
- if (userProperties) {
13
- this.identityStore.editIdentity().updateUserProperties(userProperties).commit();
14
- }
15
- return context;
16
- }
17
-
18
- setup(_: Config): Promise<undefined> {
19
- return Promise.resolve(undefined);
20
- }
21
- }
@@ -1,81 +0,0 @@
1
- import { UserSession, Storage, SessionManager as ISessionManager } from '@amplitude/analytics-types';
2
- import { getCookieName as getStorageKey } from './utils/cookie-name';
3
-
4
- export class SessionManager implements ISessionManager {
5
- storageKey: string;
6
- cache: UserSession;
7
- isSessionCacheValid = true;
8
-
9
- constructor(private storage: Storage<UserSession>, apiKey: string) {
10
- this.storageKey = getStorageKey(apiKey);
11
- this.cache = { optOut: false };
12
- }
13
-
14
- /**
15
- * load() must be called immediately after instantation
16
- *
17
- * ```ts
18
- * await new SessionManager(...).load();
19
- * ```
20
- */
21
- async load() {
22
- this.cache = (await this.storage.get(this.storageKey)) ?? {
23
- optOut: false,
24
- };
25
- return this;
26
- }
27
-
28
- setSession(session: Partial<UserSession>) {
29
- this.cache = { ...this.cache, ...session };
30
- void this.storage.set(this.storageKey, this.cache);
31
- }
32
-
33
- getSessionId() {
34
- this.isSessionCacheValid = true;
35
- void this.storage.get(this.storageKey).then((userSession) => {
36
- // Checks if session id has been set since the last get
37
- if (this.isSessionCacheValid) {
38
- this.cache.sessionId = userSession?.sessionId;
39
- }
40
- });
41
- return this.cache.sessionId;
42
- }
43
-
44
- setSessionId(sessionId: number) {
45
- // Flags session id has been set
46
- this.isSessionCacheValid = false;
47
- this.setSession({ sessionId });
48
- }
49
-
50
- getDeviceId(): string | undefined {
51
- return this.cache.deviceId;
52
- }
53
-
54
- setDeviceId(deviceId: string): void {
55
- this.setSession({ deviceId });
56
- }
57
-
58
- getUserId(): string | undefined {
59
- return this.cache.userId;
60
- }
61
-
62
- setUserId(userId: string): void {
63
- this.setSession({ userId });
64
- }
65
-
66
- getLastEventTime() {
67
- return this.cache.lastEventTime;
68
- }
69
-
70
- setLastEventTime(lastEventTime: number) {
71
- this.setSession({ lastEventTime });
72
- }
73
-
74
- getOptOut(): boolean {
75
- return this.cache.optOut;
76
- }
77
-
78
- setOptOut(optOut: boolean): void {
79
- this.setSession({ optOut });
80
- }
81
- }
@@ -1,97 +0,0 @@
1
- import { Storage, CookieStorageOptions } from '@amplitude/analytics-types';
2
- import { isNative } from '../utils/platform';
3
-
4
- export class CookieStorage<T> implements Storage<T> {
5
- options: CookieStorageOptions;
6
-
7
- constructor(options?: CookieStorageOptions) {
8
- this.options = { ...options };
9
- }
10
-
11
- async isEnabled(): Promise<boolean> {
12
- /* istanbul ignore if */
13
- if (isNative() || typeof window === 'undefined') {
14
- return false;
15
- }
16
-
17
- const random = String(Date.now());
18
- const testStrorage = new CookieStorage<string>(this.options);
19
- const testKey = 'AMP_TEST';
20
- try {
21
- await testStrorage.set(testKey, random);
22
- const value = await testStrorage.get(testKey);
23
- return value === random;
24
- } catch {
25
- /* istanbul ignore next */
26
- return false;
27
- } finally {
28
- await testStrorage.remove(testKey);
29
- }
30
- }
31
-
32
- async get(key: string): Promise<T | undefined> {
33
- let value = await this.getRaw(key);
34
- if (!value) {
35
- return undefined;
36
- }
37
- try {
38
- try {
39
- value = decodeURIComponent(atob(value));
40
- } catch {
41
- // value not encoded
42
- }
43
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
44
- return JSON.parse(value);
45
- } catch {
46
- /* istanbul ignore next */
47
- return undefined;
48
- }
49
- }
50
-
51
- async getRaw(key: string): Promise<string | undefined> {
52
- const cookie = window.document.cookie.split('; ');
53
- const match = cookie.find((c) => c.indexOf(key + '=') === 0);
54
- if (!match) {
55
- return undefined;
56
- }
57
- return match.substring(key.length + 1);
58
- }
59
-
60
- async set(key: string, value: T | null): Promise<void> {
61
- try {
62
- const expirationDays = this.options.expirationDays ?? 0;
63
- const expires = value !== null ? expirationDays : -1;
64
- let expireDate: Date | undefined = undefined;
65
- if (expires) {
66
- const date = new Date();
67
- date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
68
- expireDate = date;
69
- }
70
- let str = `${key}=${btoa(encodeURIComponent(JSON.stringify(value)))}`;
71
- if (expireDate) {
72
- str += `; expires=${expireDate.toUTCString()}`;
73
- }
74
- str += '; path=/';
75
- if (this.options.domain) {
76
- str += `; domain=${this.options.domain}`;
77
- }
78
- if (this.options.secure) {
79
- str += '; Secure';
80
- }
81
- if (this.options.sameSite) {
82
- str += `; SameSite=${this.options.sameSite}`;
83
- }
84
- window.document.cookie = str;
85
- } catch {
86
- //
87
- }
88
- }
89
-
90
- async remove(key: string): Promise<void> {
91
- await this.set(key, null);
92
- }
93
-
94
- async reset(): Promise<void> {
95
- return;
96
- }
97
- }