@molecule/app-analytics-mixpanel 1.0.2 → 1.0.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/LICENSE +111 -24
- package/README.md +37 -32
- package/dist/provider.d.ts +5 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +117 -0
- package/dist/provider.js.map +1 -1
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
Apache License
|
|
2
3
|
Version 2.0, January 2004
|
|
3
4
|
http://www.apache.org/licenses/
|
|
@@ -34,21 +35,33 @@
|
|
|
34
35
|
|
|
35
36
|
"Work" shall mean the work of authorship, whether in Source or
|
|
36
37
|
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
38
40
|
|
|
39
41
|
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
42
|
form, that is based on (or derived from) the Work and for which the
|
|
41
43
|
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
-
represent, as a whole, an original work of authorship.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
49
62
|
|
|
50
63
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
-
on behalf of whom a Contribution has been received by
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
52
65
|
subsequently incorporated within the Work.
|
|
53
66
|
|
|
54
67
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
@@ -61,8 +74,18 @@
|
|
|
61
74
|
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
75
|
this License, each Contributor hereby grants to You a perpetual,
|
|
63
76
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
-
|
|
65
|
-
and otherwise transfer the Work
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
66
89
|
|
|
67
90
|
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
91
|
Work or Derivative Works thereof in any medium, with or without
|
|
@@ -84,23 +107,87 @@
|
|
|
84
107
|
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
108
|
distribution, then any Derivative Works that You distribute must
|
|
86
109
|
include a readable copy of the attribution notices contained
|
|
87
|
-
within such NOTICE file
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
90
138
|
|
|
91
139
|
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
-
names, trademarks, service marks, or product names of the Licensor
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
93
143
|
|
|
94
144
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
-
agreed to in writing, Licensor provides the Work
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
104
191
|
|
|
105
192
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
193
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -3,17 +3,17 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-11-01T06:11:47.514Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-analytics-mixpanel
|
|
10
10
|
|
|
11
|
+
Mixpanel analytics provider for molecule.dev frontend.
|
|
12
|
+
|
|
11
13
|
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
12
14
|
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
13
15
|
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
14
16
|
|
|
15
|
-
Mixpanel analytics provider for molecule.dev frontend.
|
|
16
|
-
|
|
17
17
|
## Quick Start
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
@@ -44,6 +44,34 @@ npm install @molecule/app-analytics-mixpanel @molecule/app-analytics mixpanel-br
|
|
|
44
44
|
|
|
45
45
|
### Interfaces
|
|
46
46
|
|
|
47
|
+
#### `MixpanelOptions`
|
|
48
|
+
|
|
49
|
+
Options for creating a Mixpanel provider.
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
interface MixpanelOptions {
|
|
53
|
+
token?: string
|
|
54
|
+
debug?: boolean
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### `AnalyticsUserProps`
|
|
59
|
+
|
|
60
|
+
User properties for analytics identification.
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface AnalyticsUserProps {
|
|
64
|
+
/** Unique user identifier. */
|
|
65
|
+
userId: string
|
|
66
|
+
/** User email address. */
|
|
67
|
+
email?: string
|
|
68
|
+
/** User display name. */
|
|
69
|
+
name?: string
|
|
70
|
+
/** Arbitrary key-value traits to associate with the user. */
|
|
71
|
+
traits?: Record<string, unknown>
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
47
75
|
#### `AnalyticsEvent`
|
|
48
76
|
|
|
49
77
|
Event properties for analytics tracking.
|
|
@@ -140,34 +168,6 @@ interface AnalyticsProvider {
|
|
|
140
168
|
}
|
|
141
169
|
```
|
|
142
170
|
|
|
143
|
-
#### `AnalyticsUserProps`
|
|
144
|
-
|
|
145
|
-
User properties for analytics identification.
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
interface AnalyticsUserProps {
|
|
149
|
-
/** Unique user identifier. */
|
|
150
|
-
userId: string
|
|
151
|
-
/** User email address. */
|
|
152
|
-
email?: string
|
|
153
|
-
/** User display name. */
|
|
154
|
-
name?: string
|
|
155
|
-
/** Arbitrary key-value traits to associate with the user. */
|
|
156
|
-
traits?: Record<string, unknown>
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
#### `MixpanelOptions`
|
|
161
|
-
|
|
162
|
-
Options for creating a Mixpanel provider.
|
|
163
|
-
|
|
164
|
-
```typescript
|
|
165
|
-
interface MixpanelOptions {
|
|
166
|
-
token?: string
|
|
167
|
-
debug?: boolean
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
171
|
### Functions
|
|
172
172
|
|
|
173
173
|
#### `createProvider(options)`
|
|
@@ -184,6 +184,11 @@ VITE_MIXPANEL_TOKEN and returns a no-op provider, so bonding the lazy
|
|
|
184
184
|
`provider` export without configuration degrades gracefully instead of
|
|
185
185
|
becoming a silent event black hole.
|
|
186
186
|
|
|
187
|
+
SDK-added location/referrer properties are scrubbed at `before_send_events`,
|
|
188
|
+
`before_send_people` and `before_send_groups`. Skip-hooks identify/alias tuples are captured
|
|
189
|
+
at `on_track`; ordinary events walk only at their final event hook. Hooks are composed AFTER
|
|
190
|
+
init so a pre-initialized singleton keeps its existing hooks and the scrubber always runs last.
|
|
191
|
+
|
|
187
192
|
```typescript
|
|
188
193
|
function createProvider(options?: MixpanelOptions): AnalyticsProvider
|
|
189
194
|
```
|
|
@@ -232,7 +237,7 @@ if (token) {
|
|
|
232
237
|
|
|
233
238
|
Peer dependencies:
|
|
234
239
|
|
|
235
|
-
- `@molecule/app-analytics` ^1.
|
|
240
|
+
- `@molecule/app-analytics` ^1.1.1
|
|
236
241
|
|
|
237
242
|
### Environment Variables
|
|
238
243
|
|
package/dist/provider.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ import type { MixpanelOptions } from './types.js';
|
|
|
20
20
|
* `provider` export without configuration degrades gracefully instead of
|
|
21
21
|
* becoming a silent event black hole.
|
|
22
22
|
*
|
|
23
|
+
* SDK-added location/referrer properties are scrubbed at `before_send_events`,
|
|
24
|
+
* `before_send_people` and `before_send_groups`. Skip-hooks identify/alias tuples are captured
|
|
25
|
+
* at `on_track`; ordinary events walk only at their final event hook. Hooks are composed AFTER
|
|
26
|
+
* init so a pre-initialized singleton keeps its existing hooks and the scrubber always runs last.
|
|
27
|
+
*
|
|
23
28
|
* @param options - Mixpanel configuration including `token` and optional `debug` flag.
|
|
24
29
|
* @returns An `AnalyticsProvider` backed by the Mixpanel browser SDK.
|
|
25
30
|
*/
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,yBAAyB,CAAA;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA6HjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,eAAe,KAAG,iBAgF1D,CAAA;AAID,8DAA8D;AAC9D,eAAO,MAAM,QAAQ,EAAE,iBAUrB,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -6,6 +6,106 @@
|
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
8
8
|
import mixpanel from 'mixpanel-browser';
|
|
9
|
+
import { snapshotAnalyticsSdkUrls } from '@molecule/app-analytics';
|
|
10
|
+
/** One inert final capture shared by event, person and group transport hooks. */
|
|
11
|
+
const scrubSdkPayload = (payload) => snapshotAnalyticsSdkUrls(payload);
|
|
12
|
+
/** The SDK accepts ordered hook arrays at runtime; append without duplicating on HMR/re-bonding. */
|
|
13
|
+
const appendHook = (configured, hook) => {
|
|
14
|
+
const previous = Array.isArray(configured) ? configured : configured ? [configured] : [];
|
|
15
|
+
return [...previous.filter((candidate) => candidate !== hook), hook];
|
|
16
|
+
};
|
|
17
|
+
const TRACK_HOOK_HISTORY = Symbol('molecule.mixpanelTrackHookHistory');
|
|
18
|
+
const REPLAY_FETCH_CAPTURE = Symbol.for('@molecule/app-analytics-mixpanel/replay-fetch-capture');
|
|
19
|
+
/** Identify only this Mixpanel instance's replay endpoint, never an application's /record route. */
|
|
20
|
+
const isReplayRequest = (input) => {
|
|
21
|
+
const raw = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
22
|
+
try {
|
|
23
|
+
const url = new URL(raw);
|
|
24
|
+
const instance = mixpanel;
|
|
25
|
+
const host = instance.get_api_host?.('record') ?? mixpanel.get_config('api_host');
|
|
26
|
+
return url.origin === new URL(host).origin && /\/record\/?$/.test(url.pathname);
|
|
27
|
+
}
|
|
28
|
+
catch (_error) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** Capture each decoded metadata value while retaining SDK identifiers and safe URL components. */
|
|
33
|
+
const scrubReplayUrl = (input) => {
|
|
34
|
+
const raw = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
35
|
+
const url = new URL(raw);
|
|
36
|
+
const entries = [];
|
|
37
|
+
url.searchParams.forEach((value, name) => entries.push([name, value]));
|
|
38
|
+
for (const [name, value] of entries) {
|
|
39
|
+
const captured = snapshotAnalyticsSdkUrls(value);
|
|
40
|
+
if (captured !== value)
|
|
41
|
+
url.searchParams.set(name, captured);
|
|
42
|
+
}
|
|
43
|
+
return url.toString();
|
|
44
|
+
};
|
|
45
|
+
/** Scrub the recorder's JSON before fetch, including its optional gzip representation. */
|
|
46
|
+
const scrubReplayBody = async (body, gzip) => {
|
|
47
|
+
if (typeof body === 'string')
|
|
48
|
+
return snapshotAnalyticsSdkUrls(body);
|
|
49
|
+
if (!gzip || typeof Blob === 'undefined' || !(body instanceof Blob))
|
|
50
|
+
return body;
|
|
51
|
+
if (typeof DecompressionStream === 'undefined' || typeof CompressionStream === 'undefined') {
|
|
52
|
+
throw new Error('Mixpanel replay transport capture is unavailable');
|
|
53
|
+
}
|
|
54
|
+
const text = await new Response(body.stream().pipeThrough(new DecompressionStream('gzip'))).text();
|
|
55
|
+
const captured = snapshotAnalyticsSdkUrls(text);
|
|
56
|
+
if (captured === text)
|
|
57
|
+
return body;
|
|
58
|
+
const compressed = new Blob([captured]).stream().pipeThrough(new CompressionStream('gzip'));
|
|
59
|
+
return new Response(compressed).blob();
|
|
60
|
+
};
|
|
61
|
+
/** Session replay bypasses Mixpanel hooks; make fetch its final data-only capture point. */
|
|
62
|
+
const installReplayTransportCapture = () => {
|
|
63
|
+
if (typeof window === 'undefined' || typeof window.fetch !== 'function')
|
|
64
|
+
return;
|
|
65
|
+
const original = window.fetch;
|
|
66
|
+
if (original[REPLAY_FETCH_CAPTURE])
|
|
67
|
+
return;
|
|
68
|
+
const captured = function (input, init) {
|
|
69
|
+
if (!isReplayRequest(input))
|
|
70
|
+
return Reflect.apply(original, this, [input, init]);
|
|
71
|
+
const gzip = new URL(typeof input === 'string' ? input : input instanceof URL ? input.href : input.url).searchParams.get('format') === 'gzip';
|
|
72
|
+
return scrubReplayBody(init?.body, gzip).then((body) => Reflect.apply(original, this, [scrubReplayUrl(input), { ...init, body }]));
|
|
73
|
+
};
|
|
74
|
+
Object.defineProperty(captured, REPLAY_FETCH_CAPTURE, { value: true });
|
|
75
|
+
window.fetch = captured;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Preserve the original event name to recognize skip-hooks identify/alias events after app hooks.
|
|
79
|
+
* Ordinary events return their original property object and walk only in before_send_events.
|
|
80
|
+
*/
|
|
81
|
+
const composeTrackHook = (configured) => {
|
|
82
|
+
const configuredHooks = Array.isArray(configured) ? configured : configured ? [configured] : [];
|
|
83
|
+
const previous = configuredHooks.flatMap((candidate) => candidate[TRACK_HOOK_HISTORY] ?? [candidate]);
|
|
84
|
+
const hook = (eventName, properties) => {
|
|
85
|
+
let name = eventName;
|
|
86
|
+
let currentProperties = properties;
|
|
87
|
+
for (const previousHook of previous) {
|
|
88
|
+
const result = previousHook(name, currentProperties);
|
|
89
|
+
if (result === null)
|
|
90
|
+
return null;
|
|
91
|
+
if (typeof result === 'string')
|
|
92
|
+
name = result;
|
|
93
|
+
else if (Array.isArray(result)) {
|
|
94
|
+
if (typeof result[0] === 'string')
|
|
95
|
+
name = result[0];
|
|
96
|
+
if (result.length > 1)
|
|
97
|
+
currentProperties = result[1];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (eventName !== '$identify' && eventName !== '$create_alias') {
|
|
101
|
+
return [name, currentProperties];
|
|
102
|
+
}
|
|
103
|
+
const captured = scrubSdkPayload({ event: name, properties: currentProperties });
|
|
104
|
+
return [captured.event, captured.properties];
|
|
105
|
+
};
|
|
106
|
+
Object.defineProperty(hook, TRACK_HOOK_HISTORY, { value: previous });
|
|
107
|
+
return hook;
|
|
108
|
+
};
|
|
9
109
|
/**
|
|
10
110
|
* Creates a Mixpanel analytics provider using `mixpanel-browser`. Initializes the SDK
|
|
11
111
|
* with the provided token and returns an `AnalyticsProvider` that maps molecule events to
|
|
@@ -19,6 +119,11 @@ import mixpanel from 'mixpanel-browser';
|
|
|
19
119
|
* `provider` export without configuration degrades gracefully instead of
|
|
20
120
|
* becoming a silent event black hole.
|
|
21
121
|
*
|
|
122
|
+
* SDK-added location/referrer properties are scrubbed at `before_send_events`,
|
|
123
|
+
* `before_send_people` and `before_send_groups`. Skip-hooks identify/alias tuples are captured
|
|
124
|
+
* at `on_track`; ordinary events walk only at their final event hook. Hooks are composed AFTER
|
|
125
|
+
* init so a pre-initialized singleton keeps its existing hooks and the scrubber always runs last.
|
|
126
|
+
*
|
|
22
127
|
* @param options - Mixpanel configuration including `token` and optional `debug` flag.
|
|
23
128
|
* @returns An `AnalyticsProvider` backed by the Mixpanel browser SDK.
|
|
24
129
|
*/
|
|
@@ -45,6 +150,18 @@ export const createProvider = (options) => {
|
|
|
45
150
|
debug: options?.debug ?? false,
|
|
46
151
|
track_pageview: false, // We handle page views manually via auto-tracking
|
|
47
152
|
});
|
|
153
|
+
const configuredHooks = mixpanel.get_config('hooks');
|
|
154
|
+
const hooks = {
|
|
155
|
+
...configuredHooks,
|
|
156
|
+
before_send_events: appendHook(configuredHooks?.before_send_events, scrubSdkPayload),
|
|
157
|
+
before_send_people: appendHook(configuredHooks?.before_send_people, scrubSdkPayload),
|
|
158
|
+
before_send_groups: appendHook(configuredHooks?.before_send_groups, scrubSdkPayload),
|
|
159
|
+
on_track: composeTrackHook(configuredHooks?.on_track),
|
|
160
|
+
};
|
|
161
|
+
// mixpanel-browser 2.84.0 accepts hook arrays and before_send_people at runtime,
|
|
162
|
+
// although its published Config declaration omits both.
|
|
163
|
+
mixpanel.set_config({ hooks });
|
|
164
|
+
installReplayTransportCapture();
|
|
48
165
|
return {
|
|
49
166
|
async identify(user) {
|
|
50
167
|
mixpanel.identify(user.userId);
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,QAAQ,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,QAAyB,MAAM,kBAAkB,CAAA;AAQxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAIlE,iFAAiF;AACjF,MAAM,eAAe,GAAG,CAAI,OAAU,EAAK,EAAE,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAA;AAa/E,oGAAoG;AACpG,MAAM,UAAU,GAAG,CAAI,UAA+B,EAAE,IAAO,EAAO,EAAE;IACtE,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACxF,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,C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E,MAAgC;YAC3D,QAAQ,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;YACtC,IAAI,MAAM,EAAE,CAAC;gBACX,QAAQ,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACpD,CAAC;QACH,CAAC;QAED,KAAK,CAAC,KAAK;YACT,QAAQ,CAAC,KAAK,EAAE,CAAA;QAClB,CAAC;QAED,KAAK,CAAC,KAAK;YACT,sEAAsE;QACxE,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AAED,4FAA4F;AAC5F,IAAI,SAAS,GAA6B,IAAI,CAAA;AAC9C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,QAAQ,GAAsB,IAAI,KAAK,CAAC,EAAuB,EAAE;IAC5E,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ;QACnB,IAAI,CAAC,SAAS;YAAE,SAAS,GAAG,cAAc,EAAE,CAAA;QAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC/C,CAAC;IACD,uKAAuK;IACvK,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK;QAChB,IAAI,CAAC,SAAS;YAAE,SAAS,GAAG,cAAc,EAAE,CAAA;QAC5C,OAAO,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;IAC5C,CAAC;CACF,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-analytics-mixpanel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Mixpanel analytics provider for molecule.dev frontend",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"mixpanel-browser": "2.
|
|
30
|
+
"mixpanel-browser": "2.84.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@molecule/app-analytics": "^1.
|
|
33
|
+
"@molecule/app-analytics": "^1.1.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@molecule/app-analytics": "1.
|
|
37
|
-
"@types/node": "26.
|
|
36
|
+
"@molecule/app-analytics": "1.1.2",
|
|
37
|
+
"@types/node": "26.6.5",
|
|
38
38
|
"typescript": "6.0.3",
|
|
39
|
-
"vitest": "4.1.
|
|
39
|
+
"vitest": "4.1.12"
|
|
40
40
|
},
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|