@takeal/cusfront-sdk 0.8.3 → 0.9.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.
- package/CHANGELOG.md +88 -1
- package/README.md +70 -12
- package/dist/analytics.cjs +74 -22
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.d.cts +43 -4
- package/dist/analytics.d.ts +43 -4
- package/dist/analytics.js +71 -23
- package/dist/analytics.js.map +1 -1
- package/dist/{cards-BPu8Ill7.d.cts → cards-C5rk0XkI.d.cts} +83 -8
- package/dist/{cards-DP1fJc_c.d.ts → cards-CS-oxqLS.d.ts} +83 -8
- package/dist/index.cjs +122 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -6
- package/dist/index.d.ts +14 -6
- package/dist/index.js +119 -28
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/resources/auth.cjs +28 -1
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +57 -5
- package/dist/resources/auth.d.ts +57 -5
- package/dist/resources/auth.js +28 -1
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/branding.cjs.map +1 -1
- package/dist/resources/branding.d.cts +6 -0
- package/dist/resources/branding.d.ts +6 -0
- package/dist/resources/branding.js.map +1 -1
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +1 -1
- package/dist/resources/cards.d.ts +1 -1
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/deposits.cjs.map +1 -1
- package/dist/resources/deposits.d.cts +1 -1
- package/dist/resources/deposits.d.ts +1 -1
- package/dist/resources/deposits.js.map +1 -1
- package/dist/resources/funding-options.d.cts +1 -1
- package/dist/resources/funding-options.d.ts +1 -1
- package/dist/resources/me.d.cts +1 -1
- package/dist/resources/me.d.ts +1 -1
- package/dist/resources/subscription.cjs.map +1 -1
- package/dist/resources/subscription.d.cts +4 -0
- package/dist/resources/subscription.d.ts +4 -0
- package/dist/resources/subscription.js.map +1 -1
- package/dist/telegram.cjs +48 -5
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +1 -1
- package/dist/telegram.d.ts +1 -1
- package/dist/telegram.js +48 -5
- package/dist/telegram.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,94 @@ All notable changes to `@takeal/cusfront-sdk` are documented here. The format
|
|
|
4
4
|
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project
|
|
5
5
|
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
## [
|
|
7
|
+
## [0.9.0] — 2026-11-26
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Session recording on public pages. With `posthog.sessionRecording: true`
|
|
12
|
+
PostHog now records the site too, and a visit from the home page through
|
|
13
|
+
sign-up into the cabinet is one recording. On public pages every input is
|
|
14
|
+
masked and the page text is kept; in the cabinet and the Mini App all text
|
|
15
|
+
and every input stay masked. A zone change switches the masking without
|
|
16
|
+
stopping the recording. If the SDK can't tell which zone the page is in, it
|
|
17
|
+
masks everything.
|
|
18
|
+
- `ZONE_ATTRIBUTE` (`data-analytics-zone`): put it on the cabinet layout's
|
|
19
|
+
root and text inside it is masked from the first render, even if
|
|
20
|
+
`setAnalyticsZone` comes late. `MASK_TEXT_CLASS` (`ph-mask`) masks an
|
|
21
|
+
element's text on every page, for a header that shows the user's e-mail or
|
|
22
|
+
balance.
|
|
23
|
+
- `Branding.status_url`: the address of the deployment's status page, when
|
|
24
|
+
it has one (platform 0.9.0 and later). Show a "Status" link only when it is
|
|
25
|
+
set.
|
|
26
|
+
- `setAnalyticsConsent(granted)`: a refusal in an open tab stops the
|
|
27
|
+
recording, opts PostHog out and silences Metrica; agreeing again resumes
|
|
28
|
+
them. `initAnalytics({ consent: false })` loads nothing until then.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- `client.ready()` throws again while the platform is down. The edge in
|
|
33
|
+
front of it now answers such requests with a 503 of its own instead of a
|
|
34
|
+
502, and the SDK took that answer for a degraded platform with an unknown
|
|
35
|
+
version. The platform's own degraded answer is read as before.
|
|
36
|
+
- `ApiError.retryAfterSeconds`: how long the server asked to wait before
|
|
37
|
+
trying again, when it said so. The SDK doesn't retry by itself.
|
|
38
|
+
|
|
39
|
+
### Changed
|
|
40
|
+
|
|
41
|
+
- Call `setAnalyticsZone("cabinet")` before the cabinet renders. Text the
|
|
42
|
+
recorder already saw on a public page stays readable in the recording, so
|
|
43
|
+
mark anything personal that stays on screen across the move with
|
|
44
|
+
`ph-mask` or `ph-no-capture`.
|
|
45
|
+
|
|
46
|
+
## [0.8.5] — 2026-11-25
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- A card order takes a promo code for top-ups. Where the way of paying has its
|
|
51
|
+
fee in the exchange rate (SBP usually does), the code lowers that fee, after
|
|
52
|
+
the user's plan. `CardOrder.rate` and `CardOrderQuote.rate` (type
|
|
53
|
+
`CardOrderRate`) say what the order was priced with: `effective_rate`,
|
|
54
|
+
`fee_bps`, `list_fee_bps`, `fee_kind` and `promo_code`. `rate` is `null` when
|
|
55
|
+
the payment is in the card's currency. A code whose minimum is above the
|
|
56
|
+
money that goes onto the card comes back `rejected` with
|
|
57
|
+
`reason: "below_minimum"` and a `message` to show. Needs platform 0.8.5;
|
|
58
|
+
older platforms leave `rate` out.
|
|
59
|
+
|
|
60
|
+
### Changed
|
|
61
|
+
|
|
62
|
+
- Types regenerated from platform 0.8.5.
|
|
63
|
+
|
|
64
|
+
## [0.8.4] — 2026-11-25
|
|
65
|
+
|
|
66
|
+
### Added
|
|
67
|
+
|
|
68
|
+
- `UserSubscription.tier_icon_url`: the picture the operator gave the plan,
|
|
69
|
+
WebP or SVG, or `null` when it has none. Needs platform 0.8.4; older
|
|
70
|
+
platforms leave it out.
|
|
71
|
+
- `deposits.quote()` takes `promo_code`. Where a method's fee is in the rate
|
|
72
|
+
(SBP, for one), the user's plan and a promo code with a percentage off the
|
|
73
|
+
top-up fee lower that fee, and the quote is priced with it. The quote says
|
|
74
|
+
so: `fee_bps` is the user's fee, `list_fee_bps` the method's before the
|
|
75
|
+
discounts, `fee_discount` what they add to `credited_amount`, and
|
|
76
|
+
`promo_code` the code the rate was priced with. The top-up made from the
|
|
77
|
+
quote uses that code by itself. Needs platform 0.8.4.
|
|
78
|
+
- `FundingQuote.effective_rate`: the rate the user gets, fee and discounts
|
|
79
|
+
included. Show it instead of working a rate out from the method's terms.
|
|
80
|
+
- `auth.confirmTotpSetupEmail({ challenge_token, code })` and
|
|
81
|
+
`auth.resendTotpSetupEmail({ challenge_token })`, and the login stage
|
|
82
|
+
`totp_setup_email_required`. From platform 0.8.4 a staff account can't
|
|
83
|
+
connect an authenticator with its password alone: the first sign-in, and
|
|
84
|
+
the one after a backup code, first sends a six-digit code to the account's
|
|
85
|
+
e-mail. The right code answers `totp_setup_required` with the QR, as
|
|
86
|
+
before. `TotpSetupEmailErrorCode` lists the errors of this step.
|
|
87
|
+
|
|
88
|
+
### Changed
|
|
89
|
+
|
|
90
|
+
- `auth.verifyTotp` resolves to `JwtIssued | TotpSetupEmailRequired`. A
|
|
91
|
+
backup code never signed in: since platform 0.8.2 the server answers it
|
|
92
|
+
with the start of connecting a new authenticator, and the SDK stored that
|
|
93
|
+
answer as if it were a session. Now it stores nothing and hands the answer
|
|
94
|
+
back; check `stage` before using `access_token`.
|
|
8
95
|
|
|
9
96
|
## [0.8.3] — 2026-11-24
|
|
10
97
|
|
package/README.md
CHANGED
|
@@ -42,10 +42,16 @@ if (result.stage === "jwt") {
|
|
|
42
42
|
} else if (result.stage === "totp_required") {
|
|
43
43
|
// Step-up required. Prompt the user for their TOTP code,
|
|
44
44
|
// then call client.auth.verifyTotp({ challenge_token, code }).
|
|
45
|
+
} else if (result.stage === "totp_setup_email_required") {
|
|
46
|
+
// A staff account has to connect an authenticator first, and the password
|
|
47
|
+
// alone is not enough: a code went to result.destination_hint. Ask for it
|
|
48
|
+
// and call client.auth.confirmTotpSetupEmail({ challenge_token, code });
|
|
49
|
+
// client.auth.resendTotpSetupEmail({ challenge_token }) sends a new one.
|
|
50
|
+
// The answer is the totp_setup_required stage below.
|
|
45
51
|
} else if (result.stage === "totp_setup_required") {
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
52
|
+
// Show result.otpauth_url as a QR code, then call
|
|
53
|
+
// client.auth.completeTotpSetup({ challenge_token, code }) and show the
|
|
54
|
+
// backup_codes it returns. They are never sent again.
|
|
49
55
|
}
|
|
50
56
|
```
|
|
51
57
|
|
|
@@ -352,6 +358,22 @@ if (q.preliminary) {
|
|
|
352
358
|
A quote reserves nothing. Drop a `rejected` code from the order: an order
|
|
353
359
|
that keeps it is refused.
|
|
354
360
|
|
|
361
|
+
A promo code for top-ups works on an order too. Where the way of paying has
|
|
362
|
+
its fee in the exchange rate (SBP usually does), the code lowers that fee,
|
|
363
|
+
after the user's plan, and the amount to pay gets smaller:
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
// q.rate.fee_bps 1900, q.rate.list_fee_bps 2000, q.rate.promo_code "FRIENDS"
|
|
367
|
+
const perUnit = 1 / Number(q.rate!.effective_rate); // roubles per unit of the card's currency
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
`rate` is null when the payment is in the card's currency. Show the rate from
|
|
371
|
+
`rate.effective_rate` and don't work it out from the method's fee. The order
|
|
372
|
+
answers with the same `rate`. If such a code has a minimum amount, it is
|
|
373
|
+
compared with the money that goes onto the card, not with the card's price:
|
|
374
|
+
below it the quote comes back with the code `rejected`
|
|
375
|
+
(`reason: "below_minimum"`) and a `message` with both figures to show.
|
|
376
|
+
|
|
355
377
|
Send the amount the user saw with the order. If the order comes to something
|
|
356
378
|
else (the code was for first cards only and this user has one, or the rate
|
|
357
379
|
moved), no payment is opened and the new quote comes back:
|
|
@@ -401,25 +423,33 @@ const sbp = funder.method_terms.find((m) => m.method === "sbp")!;
|
|
|
401
423
|
// sbp.source_currency → "RUB"; sbp.fee_kind → "markup"; sbp.fee_bps → 2000;
|
|
402
424
|
// sbp.quote_ttl_seconds → 300; sbp.min_amount, sbp.max_amount, sbp.daily_limit_per_user
|
|
403
425
|
|
|
404
|
-
// 2. The user types roubles
|
|
426
|
+
// 2. The user types roubles (and a promo code, if they have one). The quote
|
|
427
|
+
// locks the rate for quote_ttl_seconds.
|
|
405
428
|
const quote = await client.deposits.quote({
|
|
406
429
|
amount: "1000",
|
|
407
430
|
currency: "RUB",
|
|
408
431
|
connectorSlug: funder.slug,
|
|
409
432
|
method: "sbp",
|
|
433
|
+
promo_code: promoCode, // optional
|
|
410
434
|
});
|
|
411
435
|
// quote.credited_amount → "10.41" USD at a bank rate of 80 ₽ and a 20 % markup.
|
|
436
|
+
// The user's plan and a promo code with a percentage off the top-up fee lower
|
|
437
|
+
// the markup: with 5 % off it is 19 %, quote.fee_bps → 1900,
|
|
438
|
+
// quote.list_fee_bps → 2000, quote.credited_amount → "10.50", and
|
|
439
|
+
// quote.promo_code names the code the rate was priced with. Don't take the fee
|
|
440
|
+
// from `sbp.fee_bps`: the quote has the user's own.
|
|
412
441
|
|
|
413
442
|
// 3. What to show. With `fee_kind === "markup"` the fee sits in the rate: show
|
|
414
443
|
// the rate and the amount credited, no fee line. The rate in the form
|
|
415
444
|
// people know, roubles per unit of the wallet currency:
|
|
416
|
-
const perUnit =
|
|
445
|
+
const perUnit = 1 / Number(quote.effective_rate); // 96.00 ₽ per $
|
|
417
446
|
show(`${quote.credited_amount} ${quote.credited_currency} at ${perUnit.toFixed(2)} ₽/$, until ${quote.expires_at}`);
|
|
418
447
|
// If the user types the wallet amount instead, work the roubles out on the
|
|
419
448
|
// client from the same rate and quote that: roubles = wanted × perUnit,
|
|
420
449
|
// rounded up to the kopeck, then `quote()` again with that amount.
|
|
421
|
-
// With `fee_kind === "commission"`
|
|
422
|
-
//
|
|
450
|
+
// With `fee_kind === "commission"` the rate is the bank's and the fee is a
|
|
451
|
+
// line of its own, taken off what is credited when the top-up settles; a
|
|
452
|
+
// plan's or a promo code's discount comes off that line.
|
|
423
453
|
|
|
424
454
|
// 4. Pay. The deposit is a redirect: send the user to the bank's page.
|
|
425
455
|
const deposit = await client.deposits.initiate({
|
|
@@ -851,6 +881,9 @@ const ref = await client.referral.get();
|
|
|
851
881
|
with a sign-up link without the user typing it again.
|
|
852
882
|
- `client.subscription.get()` shows a gift subscription as `kind: "gift"`;
|
|
853
883
|
`gift_until: null` means it doesn't end.
|
|
884
|
+
- `tier_icon_url` is the plan's own picture (WebP or SVG) that the operator
|
|
885
|
+
uploaded. When it is `null`, show your own generic one. Draw it with
|
|
886
|
+
`<img>`, not inline, so an SVG stays a picture.
|
|
854
887
|
- Rewards and code bonuses are bonuses: a discount on our services, not
|
|
855
888
|
money. Show friends without names; the API sends none.
|
|
856
889
|
|
|
@@ -1064,8 +1097,8 @@ Every page belongs to a zone, and the zone decides what is collected:
|
|
|
1064
1097
|
|---|---|---|
|
|
1065
1098
|
| PostHog autocapture | on, with element texts | on, without texts or attributes |
|
|
1066
1099
|
| Heatmaps | on | off |
|
|
1067
|
-
| Masking |
|
|
1068
|
-
| Session recording | off | off; `sessionRecording: true` turns it on
|
|
1100
|
+
| Masking in recordings | every input | every input and all text |
|
|
1101
|
+
| Session recording | off; `sessionRecording: true` turns it on | off; `sessionRecording: true` turns it on |
|
|
1069
1102
|
| Yandex Metrica | yes, without Webvisor | never |
|
|
1070
1103
|
|
|
1071
1104
|
### Public pages
|
|
@@ -1075,7 +1108,7 @@ import { initAnalytics, track, identify, posthogDistinctId } from "@takeal/cusfr
|
|
|
1075
1108
|
|
|
1076
1109
|
initAnalytics({
|
|
1077
1110
|
zone: "public",
|
|
1078
|
-
posthog: { key: "phc_…", host: "https://example.com/ingest" },
|
|
1111
|
+
posthog: { key: "phc_…", host: "https://example.com/ingest", sessionRecording: true },
|
|
1079
1112
|
metrika: { counterId: 12345678 },
|
|
1080
1113
|
});
|
|
1081
1114
|
|
|
@@ -1117,6 +1150,31 @@ Put card details, balances and the operations history inside `NO_CAPTURE_CLASS`
|
|
|
1117
1150
|
|
|
1118
1151
|
Turn on `sessionRecording: true` last, after you have watched one of your own cabinet sessions in PostHog and seen no values in it at all: no card number, balance, amount or e-mail.
|
|
1119
1152
|
|
|
1153
|
+
### Session recording
|
|
1154
|
+
|
|
1155
|
+
With `sessionRecording: true` PostHog records the visit in every zone, and a walk from the home page through sign-up into the cabinet is one recording. Without the flag nothing is recorded anywhere.
|
|
1156
|
+
|
|
1157
|
+
On public pages every input is masked and the page text is kept. In the cabinet and the Mini App every text and every input is masked. Blocks with `NO_CAPTURE_CLASS` are left out of recordings everywhere. `setAnalyticsZone` switches the masking at once and leaves the recording running.
|
|
1158
|
+
|
|
1159
|
+
The masking is decided when the recorder first sees a piece of text, and nothing goes back over what it has already recorded. Text recorded on a public page stays readable in the recording; text that first appears in the cabinet is masked. So:
|
|
1160
|
+
|
|
1161
|
+
- Call `setAnalyticsZone("cabinet")` before the cabinet renders: in the router's before-navigation hook, not after it. Going back to the site, calling it after the page has changed is fine, the masking just lasts a moment longer.
|
|
1162
|
+
- Put `data-analytics-zone="cabinet"` (`ZONE_ATTRIBUTE`) on the root element of the cabinet's layout, and `"miniapp"` on the Mini App's. Text inside it is masked from the first render even if the zone call comes late.
|
|
1163
|
+
- Anything that shows personal data outside that root and stays on screen across the move, such as a header with the user's e-mail or balance after sign-in, gets `MASK_TEXT_CLASS` (`ph-mask`, text masked on every page) or `NO_CAPTURE_CLASS` (not recorded at all). Otherwise the header the recorder saw on the public page, already holding the e-mail, stays readable.
|
|
1164
|
+
|
|
1165
|
+
When the SDK can't tell where the page is (before `initAnalytics`, an unknown zone), recordings mask everything.
|
|
1166
|
+
|
|
1167
|
+
### Consent
|
|
1168
|
+
|
|
1169
|
+
Call `initAnalytics` once the visitor has agreed to analytics cookies, or call it early with `consent: false`: then nothing loads until they agree. When the answer changes in an open tab, tell the SDK:
|
|
1170
|
+
|
|
1171
|
+
```ts
|
|
1172
|
+
setAnalyticsConsent(false); // recording stops, PostHog opts out, Metrica falls silent
|
|
1173
|
+
setAnalyticsConsent(true); // PostHog opts back in, the recording resumes when it is on
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
Deleting the analytics cookies and the kept ids on a refusal stays with the app (`forgetAnalyticsIds()` and the cookie banner's own cleanup).
|
|
1177
|
+
|
|
1120
1178
|
### Telegram Mini App
|
|
1121
1179
|
|
|
1122
1180
|
The same as the cabinet, with `zone: "miniapp"`.
|
|
@@ -1125,7 +1183,7 @@ The same as the cabinet, with `zone: "miniapp"`.
|
|
|
1125
1183
|
|
|
1126
1184
|
Metrica never loads in the cabinet or in the Mini App, even when `metrika` is passed. From the browser it gets page views and two goals, `signup_started` and `signup_completed`. Deposits, cards and subscriptions reach Metrica from the server with their amount in roubles, so the browser doesn't send them. Webvisor, the click map and link tracking are off: Metrica sees only what the SDK sends it.
|
|
1127
1185
|
|
|
1128
|
-
When the site and the cabinet are one app, call `setAnalyticsZone("cabinet")` as the user enters the cabinet. PostHog switches to masking, and Metrica stops receiving anything. A full page load into the cabinet is safer, because then Metrica isn't on the page at all. If `initAnalytics` finds Metrica on a cabinet page, it warns in the console.
|
|
1186
|
+
When the site and the cabinet are one app, call `setAnalyticsZone("cabinet")` as the user enters the cabinet, before its page renders. PostHog switches to masking, and Metrica stops receiving anything. A full page load into the cabinet is safer, because then Metrica isn't on the page at all. If `initAnalytics` finds Metrica on a cabinet page, it warns in the console.
|
|
1129
1187
|
|
|
1130
1188
|
### Events and page views
|
|
1131
1189
|
|
|
@@ -1488,7 +1546,7 @@ Available now:
|
|
|
1488
1546
|
- `@takeal/cusfront-sdk/webhooks` — HMAC-SHA256 signature verifier (no network, isomorphic).
|
|
1489
1547
|
- `@takeal/cusfront-sdk/react` — optional React hooks layer (`ClientProvider` + `useMe` / `useDeposits` / `useCards` / `useCardProducts` / `useBalance` / `useNotifications` / `useUnreadCount`). React is a `peerDependency`, never bundled.
|
|
1490
1548
|
- `@takeal/cusfront-sdk/telegram` — Telegram Mini App `initData` → authenticated client bridge.
|
|
1491
|
-
- `@takeal/cusfront-sdk/analytics` — `initAnalytics`, `track`, `page`, `identify`, `resetAnalytics`, `posthogDistinctId` (PostHog and Yandex Metrica behind one call; see [Analytics](#analytics)).
|
|
1549
|
+
- `@takeal/cusfront-sdk/analytics` — `initAnalytics`, `setAnalyticsZone`, `setAnalyticsConsent`, `track`, `page`, `identify`, `resetAnalytics`, `posthogDistinctId` (PostHog and Yandex Metrica behind one call; see [Analytics](#analytics)).
|
|
1492
1550
|
|
|
1493
1551
|
### Verifying webhooks
|
|
1494
1552
|
|
package/dist/analytics.cjs
CHANGED
|
@@ -62,6 +62,8 @@ var ANALYTICS_EVENTS = [
|
|
|
62
62
|
];
|
|
63
63
|
var METRIKA_GOALS = ["signup_started", "signup_completed"];
|
|
64
64
|
var NO_CAPTURE_CLASS = "ph-no-capture";
|
|
65
|
+
var MASK_TEXT_CLASS = "ph-mask";
|
|
66
|
+
var ZONE_ATTRIBUTE = "data-analytics-zone";
|
|
65
67
|
var UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
|
|
66
68
|
var EMAIL = /[^\s@"'<>(),;:]+@[^\s@"'<>(),;:]+\.[a-z]{2,}/gi;
|
|
67
69
|
var DIGIT_RUN = /\+?\d[\d\s().-]{7,}\d/g;
|
|
@@ -327,18 +329,38 @@ function posthogConfig(zone, o) {
|
|
|
327
329
|
// Page views go through `page()`, with a cleaned address.
|
|
328
330
|
capture_pageview: false,
|
|
329
331
|
capture_pageleave: true,
|
|
330
|
-
before_send: beforeSend
|
|
332
|
+
before_send: beforeSend,
|
|
333
|
+
// Set once. A zone change never touches these: posthog-js hands the
|
|
334
|
+
// recording options to rrweb when the recorder starts, and changing
|
|
335
|
+
// `disable_session_recording` stops or restarts it.
|
|
336
|
+
disable_session_recording: !o.sessionRecording,
|
|
337
|
+
session_recording: recordingOptions()
|
|
338
|
+
};
|
|
339
|
+
return { ...base, ...zoneConfig(zone) };
|
|
340
|
+
}
|
|
341
|
+
function recordingOptions() {
|
|
342
|
+
return {
|
|
343
|
+
maskAllInputs: true,
|
|
344
|
+
maskTextSelector: "*",
|
|
345
|
+
maskTextFn: maskRecordedText,
|
|
346
|
+
blockClass: NO_CAPTURE_CLASS
|
|
331
347
|
};
|
|
332
|
-
return { ...base, ...zoneConfig(zone, o) };
|
|
333
348
|
}
|
|
334
|
-
|
|
349
|
+
var PRIVATE_BLOCK = `.${MASK_TEXT_CLASS}, [${ZONE_ATTRIBUTE}]:not([${ZONE_ATTRIBUTE}="public"])`;
|
|
350
|
+
function maskRecordedText(text, element) {
|
|
351
|
+
try {
|
|
352
|
+
if (state()?.zone === "public" && !element?.closest(PRIVATE_BLOCK)) return text;
|
|
353
|
+
} catch {
|
|
354
|
+
}
|
|
355
|
+
return text.replace(/\S/g, "*");
|
|
356
|
+
}
|
|
357
|
+
function zoneConfig(zone) {
|
|
335
358
|
if (zone === "public") {
|
|
336
359
|
return {
|
|
337
360
|
autocapture: true,
|
|
338
361
|
mask_all_text: false,
|
|
339
362
|
mask_all_element_attributes: false,
|
|
340
|
-
enable_heatmaps: true
|
|
341
|
-
disable_session_recording: true
|
|
363
|
+
enable_heatmaps: true
|
|
342
364
|
};
|
|
343
365
|
}
|
|
344
366
|
return {
|
|
@@ -346,13 +368,7 @@ function zoneConfig(zone, o) {
|
|
|
346
368
|
autocapture: { capture_copied_text: false },
|
|
347
369
|
mask_all_text: true,
|
|
348
370
|
mask_all_element_attributes: true,
|
|
349
|
-
enable_heatmaps: false
|
|
350
|
-
disable_session_recording: !o.sessionRecording,
|
|
351
|
-
session_recording: {
|
|
352
|
-
maskAllInputs: true,
|
|
353
|
-
maskTextSelector: "*",
|
|
354
|
-
blockClass: NO_CAPTURE_CLASS
|
|
355
|
-
}
|
|
371
|
+
enable_heatmaps: false
|
|
356
372
|
};
|
|
357
373
|
}
|
|
358
374
|
function assetsHost(o) {
|
|
@@ -411,16 +427,26 @@ var PostHogSink = class {
|
|
|
411
427
|
}
|
|
412
428
|
setZone(zone) {
|
|
413
429
|
this.with((ph) => {
|
|
414
|
-
ph.set_config(zoneConfig(zone
|
|
430
|
+
ph.set_config(zoneConfig(zone));
|
|
415
431
|
ph.register({ zone });
|
|
416
|
-
|
|
417
|
-
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
setConsent(granted) {
|
|
435
|
+
this.with((ph) => {
|
|
436
|
+
if (granted) {
|
|
437
|
+
ph.opt_in_capturing?.();
|
|
438
|
+
if (this.o.sessionRecording) ph.startSessionRecording?.();
|
|
439
|
+
} else {
|
|
440
|
+
ph.stopSessionRecording?.();
|
|
441
|
+
ph.opt_out_capturing?.();
|
|
442
|
+
}
|
|
418
443
|
});
|
|
419
444
|
}
|
|
420
445
|
};
|
|
421
446
|
var MetrikaSink = class {
|
|
422
447
|
constructor(o) {
|
|
423
448
|
this.live = true;
|
|
449
|
+
this.consented = true;
|
|
424
450
|
this.id = Number(o.counterId);
|
|
425
451
|
const w = win();
|
|
426
452
|
if (!w.ym) {
|
|
@@ -443,7 +469,7 @@ var MetrikaSink = class {
|
|
|
443
469
|
});
|
|
444
470
|
}
|
|
445
471
|
ym(...args) {
|
|
446
|
-
if (this.live) win().ym?.(this.id, ...args);
|
|
472
|
+
if (this.live && this.consented) win().ym?.(this.id, ...args);
|
|
447
473
|
}
|
|
448
474
|
capture(event, props) {
|
|
449
475
|
if (METRIKA_GOALS.includes(event)) this.ym("reachGoal", event, props);
|
|
@@ -459,16 +485,27 @@ var MetrikaSink = class {
|
|
|
459
485
|
setZone(zone) {
|
|
460
486
|
this.live = zone === "public";
|
|
461
487
|
}
|
|
488
|
+
setConsent(granted) {
|
|
489
|
+
this.consented = granted;
|
|
490
|
+
}
|
|
462
491
|
};
|
|
463
492
|
var KEY = /* @__PURE__ */ Symbol.for("takeal.cusfront-sdk.analytics");
|
|
464
493
|
var holder = globalThis;
|
|
465
494
|
var state = () => holder[KEY];
|
|
495
|
+
function loaded(s) {
|
|
496
|
+
return [s.posthog, s.metrika].filter((x) => !!x);
|
|
497
|
+
}
|
|
466
498
|
function sinks(s) {
|
|
499
|
+
if (!s.consent) return [];
|
|
500
|
+
if (s.options.posthog?.key && !s.posthog) {
|
|
501
|
+
s.posthog = new PostHogSink(s.options.posthog, s.zone);
|
|
502
|
+
if (s.userId) s.posthog.identify(s.userId);
|
|
503
|
+
}
|
|
467
504
|
if (s.zone === "public" && s.options.metrika && !s.metrika) {
|
|
468
505
|
s.metrika = new MetrikaSink(s.options.metrika);
|
|
469
506
|
if (s.userId) s.metrika.identify(s.userId);
|
|
470
507
|
}
|
|
471
|
-
return
|
|
508
|
+
return loaded(s);
|
|
472
509
|
}
|
|
473
510
|
function initAnalytics(options) {
|
|
474
511
|
if (state() || !win().document) return;
|
|
@@ -477,17 +514,28 @@ function initAnalytics(options) {
|
|
|
477
514
|
"[analytics] Yandex Metrica is on a page outside the public zone; it must not be."
|
|
478
515
|
);
|
|
479
516
|
}
|
|
480
|
-
const s = { options, zone: options.zone };
|
|
517
|
+
const s = { options, zone: options.zone, consent: options.consent !== false };
|
|
481
518
|
holder[KEY] = s;
|
|
482
|
-
if (options.posthog?.key) s.posthog = new PostHogSink(options.posthog, options.zone);
|
|
483
519
|
sinks(s);
|
|
484
520
|
if (options.initialPageview !== false) page();
|
|
485
521
|
}
|
|
522
|
+
function setAnalyticsConsent(granted) {
|
|
523
|
+
const s = state();
|
|
524
|
+
if (!s || s.consent === granted) return;
|
|
525
|
+
s.consent = granted;
|
|
526
|
+
const before = loaded(s);
|
|
527
|
+
for (const sink of before) sink.setConsent(granted);
|
|
528
|
+
if (granted) {
|
|
529
|
+
sinks(s);
|
|
530
|
+
if (s.lastPage === void 0 && s.options.initialPageview !== false) page();
|
|
531
|
+
}
|
|
532
|
+
}
|
|
486
533
|
function setAnalyticsZone(zone) {
|
|
487
534
|
const s = state();
|
|
488
535
|
if (!s || s.zone === zone) return;
|
|
489
536
|
s.zone = zone;
|
|
490
|
-
|
|
537
|
+
sinks(s);
|
|
538
|
+
for (const sink of loaded(s)) sink.setZone(zone);
|
|
491
539
|
}
|
|
492
540
|
function track(event, props = {}) {
|
|
493
541
|
const s = state();
|
|
@@ -499,7 +547,7 @@ function page(url) {
|
|
|
499
547
|
const s = state();
|
|
500
548
|
const w = win();
|
|
501
549
|
const raw = url ?? w.location?.href;
|
|
502
|
-
if (!s || !raw) return;
|
|
550
|
+
if (!s || !s.consent || !raw) return;
|
|
503
551
|
const clean2 = sanitizeUrl(raw);
|
|
504
552
|
if (clean2 === s.lastPage) return;
|
|
505
553
|
const referrer = s.lastPage ?? (w.document?.referrer ? sanitizeUrl(w.document.referrer) : void 0);
|
|
@@ -516,7 +564,7 @@ function resetAnalytics() {
|
|
|
516
564
|
const s = state();
|
|
517
565
|
if (!s) return;
|
|
518
566
|
s.userId = void 0;
|
|
519
|
-
for (const sink of
|
|
567
|
+
for (const sink of loaded(s)) sink.reset();
|
|
520
568
|
}
|
|
521
569
|
async function posthogDistinctId(timeoutMs = 3e3) {
|
|
522
570
|
const ready = state()?.posthog?.ready;
|
|
@@ -539,18 +587,22 @@ function _resetAnalyticsForTests() {
|
|
|
539
587
|
|
|
540
588
|
exports.ANALYTICS_EVENTS = ANALYTICS_EVENTS;
|
|
541
589
|
exports.CLICK_ID_PARAMS = CLICK_ID_PARAMS;
|
|
590
|
+
exports.MASK_TEXT_CLASS = MASK_TEXT_CLASS;
|
|
542
591
|
exports.METRIKA_GOALS = METRIKA_GOALS;
|
|
543
592
|
exports.NO_CAPTURE_CLASS = NO_CAPTURE_CLASS;
|
|
544
593
|
exports.UTM_PARAMS = UTM_PARAMS;
|
|
594
|
+
exports.ZONE_ATTRIBUTE = ZONE_ATTRIBUTE;
|
|
545
595
|
exports._resetAnalyticsForTests = _resetAnalyticsForTests;
|
|
546
596
|
exports.adValuePersonal = adValuePersonal;
|
|
547
597
|
exports.identify = identify;
|
|
548
598
|
exports.initAnalytics = initAnalytics;
|
|
599
|
+
exports.maskRecordedText = maskRecordedText;
|
|
549
600
|
exports.page = page;
|
|
550
601
|
exports.posthogDistinctId = posthogDistinctId;
|
|
551
602
|
exports.resetAnalytics = resetAnalytics;
|
|
552
603
|
exports.sanitizeProperties = sanitizeProperties;
|
|
553
604
|
exports.sanitizeUrl = sanitizeUrl;
|
|
605
|
+
exports.setAnalyticsConsent = setAnalyticsConsent;
|
|
554
606
|
exports.setAnalyticsZone = setAnalyticsZone;
|
|
555
607
|
exports.track = track;
|
|
556
608
|
//# sourceMappingURL=analytics.cjs.map
|