-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathtypes.ts
1635 lines (1418 loc) · 50.5 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { recordOptions } from './extensions/replay/types/rrweb'
import type { SegmentAnalytics } from './extensions/segment-integration'
import { PostHog } from './posthog-core'
import { Survey } from './posthog-surveys-types'
export type Property = any
export type Properties = Record<string, Property>
export const COPY_AUTOCAPTURE_EVENT = '$copy_autocapture'
export const knownUnsafeEditableEvent = [
'$snapshot',
'$pageview',
'$pageleave',
'$set',
'survey dismissed',
'survey sent',
'survey shown',
'$identify',
'$groupidentify',
'$create_alias',
'$$client_ingestion_warning',
'$web_experiment_applied',
'$feature_enrollment_update',
'$feature_flag_called',
] as const
/**
* These events can be processed by the `beforeCapture` function
* but can cause unexpected confusion in data.
*
* Some features of PostHog rely on receiving 100% of these events
*/
export type KnownUnsafeEditableEvent = (typeof knownUnsafeEditableEvent)[number]
/**
* These are known events PostHog events that can be processed by the `beforeCapture` function
* That means PostHog functionality does not rely on receiving 100% of these for calculations
* So, it is safe to sample them to reduce the volume of events sent to PostHog
*/
export type KnownEventName =
| '$heatmaps_data'
| '$opt_in'
| '$exception'
| '$$heatmap'
| '$web_vitals'
| '$dead_click'
| '$autocapture'
| typeof COPY_AUTOCAPTURE_EVENT
| '$rageclick'
export type EventName =
| KnownUnsafeEditableEvent
| KnownEventName
// magic value so that the type of EventName is a set of known strings or any other string
// which means you get autocomplete for known strings
// but no type complaints when you add an arbitrary string
| (string & {})
export interface CaptureResult {
uuid: string
event: EventName
properties: Properties
$set?: Properties
$set_once?: Properties
timestamp?: Date
}
export type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label'
export type DomAutocaptureEvents = 'click' | 'change' | 'submit'
/**
* If an array is passed for an allowlist, autocapture events will only be sent for elements matching
* at least one of the elements in the array. Multiple allowlists can be used
*/
export interface AutocaptureConfig {
/**
* List of URLs to allow autocapture on, can be strings to match
* or regexes e.g. ['https://example.com', 'test.com/.*']
* this is useful when you want to autocapture on specific pages only
*
* if you set both url_allowlist and url_ignorelist,
* we check the allowlist first and then the ignorelist.
* the ignorelist can override the allowlist
*/
url_allowlist?: (string | RegExp)[]
/**
* List of URLs to not allow autocapture on, can be strings to match
* or regexes e.g. ['https://example.com', 'test.com/.*']
* this is useful when you want to autocapture on most pages but not some specific ones
*
* if you set both url_allowlist and url_ignorelist,
* we check the allowlist first and then the ignorelist.
* the ignorelist can override the allowlist
*/
url_ignorelist?: (string | RegExp)[]
/**
* List of DOM events to allow autocapture on e.g. ['click', 'change', 'submit']
*/
dom_event_allowlist?: DomAutocaptureEvents[]
/**
* List of DOM elements to allow autocapture on
* e.g. ['a', 'button', 'form', 'input', 'select', 'textarea', 'label']
*
* We consider the tree of elements from the root to the target element of the click event
* so for the tree `div > div > button > svg`
* if the allowlist has `button` then we allow the capture when the `button` or the `svg` is the click target
* but not if either of the `div`s are detected as the click target
*/
element_allowlist?: AutocaptureCompatibleElement[]
/**
* List of CSS selectors to allow autocapture on
* e.g. ['[ph-capture]']
* we consider the tree of elements from the root to the target element of the click event
* so for the tree div > div > button > svg
* and allow list config `['[id]']`
* we will capture the click if the click-target or its parents has any id
*
* Everything is allowed when there's no allowlist
*/
css_selector_allowlist?: string[]
/**
* Exclude certain element attributes from autocapture
* E.g. ['aria-label'] or [data-attr-pii]
*/
element_attribute_ignorelist?: string[]
/**
* When set to true, autocapture will capture the text of any element that is cut or copied.
*/
capture_copied_text?: boolean
}
export interface BootstrapConfig {
distinctID?: string
isIdentifiedID?: boolean
featureFlags?: Record<string, boolean | string>
featureFlagPayloads?: Record<string, JsonType>
/**
* Optionally provide a sessionID, this is so that you can provide an existing sessionID here to continue a user's session across a domain or device. It MUST be:
* - unique to this user
* - a valid UUID v7
* - the timestamp part must be <= the timestamp of the first event in the session
* - the timestamp of the last event in the session must be < the timestamp part + 24 hours
* **/
sessionID?: string
}
export type SupportedWebVitalsMetrics = 'LCP' | 'CLS' | 'FCP' | 'INP'
export interface PerformanceCaptureConfig {
/**
* Works with session replay to use the browser's native performance observer to capture performance metrics
*/
network_timing?: boolean
/**
* Use chrome's web vitals library to wrap fetch and capture web vitals
*/
web_vitals?: boolean
/**
* We observe very large values reported by the Chrome web vitals library
* These outliers are likely not real, useful values, and we exclude them
* You can set this to 0 in order to include all values, NB this is not recommended
*
* @default 15 * 60 * 1000 (15 minutes)
*/
__web_vitals_max_value?: number
/**
* By default all 4 metrics are captured
* You can set this config to restrict which metrics are captured
* e.g. ['CLS', 'FCP'] to only capture those two metrics
* NB setting this does not override whether the capture is enabled
*
* @default ['LCP', 'CLS', 'FCP', 'INP']
*/
web_vitals_allowed_metrics?: SupportedWebVitalsMetrics[]
/**
* We delay flushing web vitals metrics to reduce the number of events we send
* This is the maximum time we will wait before sending the metrics
*
* @default 5000
*/
web_vitals_delayed_flush_ms?: number
}
export interface DeadClickCandidate {
node: Element
originalEvent: MouseEvent
timestamp: number
// time between click and the most recent scroll
scrollDelayMs?: number
// time between click and the most recent mutation
mutationDelayMs?: number
// time between click and the most recent selection changed event
selectionChangedDelayMs?: number
// if neither scroll nor mutation seen before threshold passed
absoluteDelayMs?: number
}
export type ExceptionAutoCaptureConfig = {
/**
* Determines whether PostHog should capture unhandled errors.
*
* @default true
*/
capture_unhandled_errors: boolean
/**
* Determines whether PostHog should capture unhandled promise rejections.
*
* @default true
*/
capture_unhandled_rejections: boolean
/**
* Determines whether PostHog should capture console errors.
*
* @default false
*/
capture_console_errors: boolean
}
export type DeadClicksAutoCaptureConfig = {
/**
* We'll not consider a click to be a dead click, if it's followed by a scroll within `scroll_threshold_ms` milliseconds
*
* @default 100
*/
scroll_threshold_ms?: number
/**
* We'll not consider a click to be a dead click, if it's followed by a selection change within `selection_change_threshold_ms` milliseconds
*
* @default 100
*/
selection_change_threshold_ms?: number
/**
* We'll not consider a click to be a dead click, if it's followed by a mutation within `mutation_threshold_ms` milliseconds
*
* @default 2500
*/
mutation_threshold_ms?: number
/**
* Allows setting behavior for when a dead click is captured.
* For e.g. to support capture to heatmaps
*
* If not provided the default behavior is to auto-capture dead click events
*
* Only intended to be provided by our own SDK
*/
__onCapture?: ((click: DeadClickCandidate, properties: Properties) => void) | undefined
} & Pick<AutocaptureConfig, 'element_attribute_ignorelist'>
export interface HeatmapConfig {
/**
* How often to send batched data in `$heatmap_data` events
* If set to 0 or not set, sends using the default interval of 1 second
*
* @default 1000
*/
flush_interval_milliseconds: number
}
export type BeforeSendFn = (cr: CaptureResult | null) => CaptureResult | null
/**
* Configuration options for the PostHog JavaScript SDK.
* @see https://posthog.com/docs/libraries/js#config
*/
export interface PostHogConfig {
/** URL of your PostHog instance.
*
* @default 'https://us.i.posthog.com'
*/
api_host: string
/**
* If using a reverse proxy for `api_host` then this should be the actual PostHog app URL (e.g. https://us.posthog.com).
* This ensures that links to PostHog point to the correct host.
*
* @default null
*/
ui_host: string | null
/**
* The transport method to use for API requests.
*
* @default 'fetch'
*/
api_transport?: 'XHR' | 'fetch'
/**
* The token for your PostHog project.
* It should NOT be provided manually in the config, but rather passed as the first parameter to `posthog.init()`.
*/
token: string
/**
* The name this instance will be identified by.
* You don't need to set this most of the time,
* but can be useful if you have several Posthog instances running at the same time.
*
* @default 'posthog'
*/
name: string
/**
* Determines whether PostHog should autocapture events.
* This setting does not affect capturing pageview events (see `capture_pageview`).
*
* @default true
*/
autocapture: boolean | AutocaptureConfig
/**
* Determines whether PostHog should capture rage clicks.
*
* @default true
*/
rageclick: boolean
/**
* Determines if cookie should be set on the top level domain (example.com).
* If PostHog-js is loaded on a subdomain (test.example.com), and `cross_subdomain_cookie` is set to false,
* it'll set the cookie on the subdomain only (test.example.com).
*
* NOTE: It will be set to `false` if we detect that the domain is a subdomain of a platform that is excluded from cross-subdomain cookie setting.
* The current list of excluded platforms is `herokuapp.com`, `vercel.app`, and `netlify.app`.
*
* @see `isCrossDomainCookie`
* @default true
*/
cross_subdomain_cookie: boolean
/**
* Determines how PostHog stores information about the user. See [persistence](https://posthog.com/docs/libraries/js#persistence) for details.
*
* @default 'localStorage+cookie'
*/
persistence: 'localStorage' | 'cookie' | 'memory' | 'localStorage+cookie' | 'sessionStorage'
/**
* The name for the super properties persistent store
*
* @default ''
*/
persistence_name: string
/** @deprecated - Use 'persistence_name' instead */
cookie_name?: string
/**
* A function to be called once the PostHog scripts have loaded successfully.
*
* @param posthog_instance - The PostHog instance that has been loaded.
*/
loaded: (posthog_instance: PostHog) => void
/**
* Determines whether PostHog should save referrer information.
*
* @default true
*/
save_referrer: boolean
/**
* Determines whether PostHog should save marketing parameters.
* These are `utm_*` paramaters and friends.
*
* @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
* @default true
*/
save_campaign_params: boolean
/** @deprecated - Use `save_campaign_params` instead */
store_google?: boolean
/**
* Used to extend the list of campaign parameters that are saved by default.
*
* @see {CAMPAIGN_PARAMS} from './utils/event-utils' - Default campaign parameters like utm_source, utm_medium, etc.
* @default []
*/
custom_campaign_params: string[]
/**
* Used to extend the list of user agents that are blocked by default.
*
* @see {DEFAULT_BLOCKED_UA_STRS} from './utils/blocked-uas' - Default list of blocked user agents.
* @default []
*/
custom_blocked_useragents: string[]
/**
* Determines whether PostHog should be in debug mode.
* You can enable this to get more detailed logging.
*
* You can also enable this on your website by appending `?__posthog_debug=true` at the end of your URL
* You can also call `posthog.debug()` in your code to enable debug mode
*
* @default false
*/
debug: boolean
/** @deprecated Use `debug` instead */
verbose?: boolean
/**
* Determines whether PostHog should capture pageview events automatically.
* Can be:
* - `true`: Capture regular pageviews (default)
* - `false`: Don't capture any pageviews
* - `'history_change'`: Only capture pageviews on history API changes (pushState, replaceState, popstate)
*
* @default true
*/
capture_pageview: boolean | 'history_change'
/**
* Determines whether PostHog should capture pageleave events.
* If set to `true`, it will capture pageleave events for all pages.
* If set to `'if_capture_pageview'`, it will only capture pageleave events if `capture_pageview` is also set to `true` or `'history_change'`.
*
* @default 'if_capture_pageview'
*/
capture_pageleave: boolean | 'if_capture_pageview'
/**
* Determines the number of days to store cookies for.
*
* @default 365
*/
cookie_expiration: number
/**
* Determines whether PostHog should upgrade old cookies.
* If set to `true`, the library will check for a cookie from our old js library and import super properties from it, then the old cookie is deleted.
* This option only works in the initialization, so make sure you set it when you create the library.
*
* @default false
*/
upgrade: boolean
/**
* Determines whether PostHog should disable session recording.
*
* @default false
*/
disable_session_recording: boolean
/**
* Determines whether PostHog should disable persistence.
* If set to `true`, the library will not save any data to the browser. It will also delete any data previously saved to the browser.
*
* @default false
*/
disable_persistence: boolean
/** @deprecated - use `disable_persistence` instead */
disable_cookie?: boolean
/**
* Determines whether PostHog should disable surveys.
*
* @default false
*/
disable_surveys: boolean
/**
* Determines whether PostHog should disable web experiments.
*
* Currently disabled while we're in BETA. It will be toggled to `true` in a future release.
*
* @default true
*/
disable_web_experiments: boolean
/**
* Determines whether PostHog should disable any external dependency loading.
* This will prevent PostHog from requesting any external scripts such as those needed for Session Replay, Surveys or Site Apps.
*
* @default false
*/
disable_external_dependency_loading: boolean
/**
* A function to be called when a script is being loaded.
* This can be used to modify the script before it is loaded.
* This is useful for adding a nonce to the script, for example.
*
* @param script - The script element that is being loaded.
* @returns The modified script element, or null if the script should not be loaded.
*/
prepare_external_dependency_script?: (script: HTMLScriptElement) => HTMLScriptElement | null
/**
* A function to be called when a stylesheet is being loaded.
* This can be used to modify the stylesheet before it is loaded.
* This is useful for adding a nonce to the stylesheet, for example.
*
* @param stylesheet - The stylesheet element that is being loaded.
* @returns The modified stylesheet element, or null if the stylesheet should not be loaded.
*/
prepare_external_dependency_stylesheet?: (stylesheet: HTMLStyleElement) => HTMLStyleElement | null
/**
* Determines whether PostHog should enable recording console logs.
* When undefined, it falls back to the remote config setting.
*
* @default undefined
*/
enable_recording_console_log?: boolean
/**
* Determines whether PostHog should use secure cookies.
* If this is `true`, PostHog cookies will be marked as secure,
* meaning they will only be transmitted over HTTPS.
*
* @default window.location.protocol === 'https:'
*/
secure_cookie: boolean
/**
* Determines whether PostHog should capture IP addresses.
*
* @default true
*/
ip: boolean
/**
* Determines if users should be opted out of PostHog tracking by default,
* requiring additional logic to opt them into capturing by calling `posthog.opt_in_capturing()`.
*
* @default false
*/
opt_out_capturing_by_default: boolean
/**
* Determines where we'll save the information about whether users are opted out of capturing.
*
* @default 'localStorage'
*/
opt_out_capturing_persistence_type: 'localStorage' | 'cookie'
/**
* Determines if users should be opted out of browser data storage by this PostHog instance by default,
* requiring additional logic to opt them into capturing by calling `posthog.opt_in_capturing()`.
*
* @default false
*/
opt_out_persistence_by_default?: boolean
/**
* Determines if users should be opted out of user agent filtering such as googlebot or other bots.
* If this is set to `true`, PostHog will set `$browser_type` to either `bot` or `browser` for all events,
* but will process all events as if they were from a browser.
*
* @default false
*/
opt_out_useragent_filter: boolean
/**
* Determines the prefix for the cookie used to store the information about whether users are opted out of capturing.
* When `null`, it falls back to the default prefix found in `consent.ts`.
*
* @default null
*/
opt_out_capturing_cookie_prefix: string | null
/**
* Determines if users should be opted in to site apps.
*
* @default false
*/
opt_in_site_apps: boolean
/**
* Determines whether PostHog should respect the Do Not Track header when computing
* consent in `ConsentManager`.
*
* @see `ConsentManager`
* @default false
*/
respect_dnt: boolean
/**
* A list of properties that should never be sent with capture calls.
*
* @default []
*/
property_denylist: string[]
/** @deprecated - use `property_denylist` instead */
property_blacklist?: string[]
/**
* A list of headers that should be sent with requests to the PostHog API.
*
* @default {}
*/
request_headers: { [header_name: string]: string }
/** @deprecated - use `request_headers` instead */
xhr_headers?: { [header_name: string]: string }
/**
* A function that is called when a request to the PostHog API fails.
*
* @param error - The `RequestResponse` object that occurred.
*/
on_request_error?: (error: RequestResponse) => void
/** @deprecated - use `on_request_error` instead */
on_xhr_error?: (failedRequest: XMLHttpRequest) => void
/**
* Determines whether PostHog should batch requests to the PostHog API.
*
* @default true
*/
request_batching: boolean
/**
* Determines the maximum length of the properties string that can be sent with capture calls.
*
* @default 65535
*/
properties_string_max_length: number
/**
* Determines the session recording options.
*
* @see `SessionRecordingOptions`
* @default {}
*/
session_recording: SessionRecordingOptions
/**
* Determines the session idle timeout in seconds.
* Any new event that's happened after this timeout will create a new session.
*
* @default 30 * 60 -- 30 minutes
*/
session_idle_timeout_seconds: number
/**
* Prevent autocapture from capturing any attribute names on elements.
*
* @default false
*/
mask_all_element_attributes: boolean
/**
* Prevent autocapture from capturing `textContent` on elements.
*
* @default false
*/
mask_all_text: boolean
/**
* Prevent autocapture from capturing personal data properties.
* These include campaign parameters, UTM parameters, and other parameters that could be considered personal data under e.g. GDPR.
*
* @default false
*/
mask_personal_data_properties: boolean
/**
* Custom list of personal data properties to mask.
*
* @default []
*/
custom_personal_data_properties: string[]
/**
* One of the very first things the PostHog library does when init() is called
* is make a request to the /decide endpoint on PostHog's backend.
* This endpoint contains information on how to run the PostHog library
* so events are properly received in the backend.
*
* This endpoint is required to run most features of the library.
* However, if you're not using any of the described features,
* you may wish to turn off the call completely to avoid an extra request
* and reduce resource usage on both the client and the server.
*
* @default false
*/
advanced_disable_decide: boolean
/**
* Will keep /decide running, but without any feature flag requests
*
* @default false
*/
advanced_disable_feature_flags: boolean
/**
* Stops from firing feature flag requests on first page load.
* Only requests feature flags when user identity or properties are updated,
* or you manually request for flags to be loaded.
*
* @default false
*/
advanced_disable_feature_flags_on_first_load: boolean
/**
* Determines whether PostHog should disable toolbar metrics.
* This is our internal instrumentation for our toolbar in your website.
*
* @default false
*/
advanced_disable_toolbar_metrics: boolean
/**
* Sets timeout for fetching feature flags
*
* @default 3000
*/
feature_flag_request_timeout_ms: number
/**
* Sets timeout for fetching surveys
*
* @default 10000
*/
surveys_request_timeout_ms: number
/**
* Function to get the device ID.
* This doesn't usually need to be set, but can be useful if you want to use a custom device ID.
*
* @param uuid - The UUID we would use for the device ID.
* @returns The device ID.
*
* @default (uuid) => uuid
*/
get_device_id: (uuid: string) => string
/**
* This function or array of functions - if provided - are called immediately before sending data to the server.
* It allows you to edit data before it is sent, or choose not to send it all.
* if provided as an array the functions are called in the order they are provided
* any one function returning null means the event will not be sent
*/
before_send?: BeforeSendFn | BeforeSendFn[]
/** @deprecated - use `before_send` instead */
sanitize_properties: ((properties: Properties, event_name: string) => Properties) | null
/** @deprecated - use `before_send` instead */
_onCapture: (eventName: string, eventData: CaptureResult) => void
/**
* Determines whether to capture performance metrics.
* These include Network Timing and Web Vitals.
*
* When `undefined`, fallback to the remote configuration.
* If `false`, neither network timing nor web vitals will work.
* If an object, that will override the remote configuration.
*
* @see {PerformanceCaptureConfig}
* @default undefined
*/
capture_performance?: boolean | PerformanceCaptureConfig
/**
* Determines whether to disable compression when sending events to the server.
* WARNING: Should only be used for testing. Could negatively impact performance.
*
* @default false
*/
disable_compression: boolean
/**
* An object containing the `distinctID`, `isIdentifiedID`, and `featureFlags` keys,
* where `distinctID` is a string, and `featureFlags` is an object of key-value pairs.
*
* Since there is a delay between initializing PostHog and fetching feature flags,
* feature flags are not always available immediately.
* This makes them unusable if you want to do something like redirecting a user
* to a different page based on a feature flag.
*
* You can, therefore, fetch the feature flags in your server and pre-fill them here,
* allowing PostHog to know the feature flag values immediately.
*
* After the SDK fetches feature flags from PostHog, it will use those flag values instead of bootstrapped ones.
*
* @default {}
*/
bootstrap: BootstrapConfig
/**
* The segment analytics object.
*
* @see https://posthog.com/docs/libraries/segment
*/
segment?: SegmentAnalytics
/**
* Determines whether to capture heatmaps.
*
* @see {HeatmapConfig}
* @default undefined
*/
capture_heatmaps?: boolean | HeatmapConfig
/* @deprecated - use `capture_heatmaps` instead */
enable_heatmaps?: boolean
/**
* Determines whether to capture dead clicks.
*
* @see {DeadClicksAutoCaptureConfig}
* @default undefined
*/
capture_dead_clicks?: boolean | DeadClicksAutoCaptureConfig
/**
* Determines whether to capture exceptions.
*
* @see {ExceptionAutoCaptureConfig}
* @default undefined
*/
capture_exceptions?: boolean | ExceptionAutoCaptureConfig
/**
* Determines whether to disable scroll properties.
* These allow you to keep track of how far down someone scrolled in your website.
*
* @default false
*/
disable_scroll_properties?: boolean
/**
* Let the pageview scroll stats use a custom css selector for the root element, e.g. `main`
* It will use `window.document.documentElement` if not specified.
*/
scroll_root_selector?: string | string[]
/**
* You can control whether events from PostHog-js have person processing enabled with the `person_profiles` config setting.
* There are three options:
* - `person_profiles: 'always'` - we will process persons data for all events
* - `person_profiles: 'never'` - we won't process persons for any event. This means that anonymous users will not be merged once they sign up or login, so you lose the ability to create funnels that track users from anonymous to identified. All events (including `$identify`) will be sent with `$process_person_profile: False`.
* - `person_profiles: 'identified_only'` _(default)_ - we will only process persons when you call `posthog.identify`, `posthog.alias`, `posthog.setPersonProperties`, `posthog.group`, `posthog.setPersonPropertiesForFlags` or `posthog.setGroupPropertiesForFlags` Anonymous users won't get person profiles.
*
* @default 'identified_only'
*/
person_profiles?: 'always' | 'never' | 'identified_only'
/** @deprecated - use `person_profiles` instead */
process_person?: 'always' | 'never' | 'identified_only'
/**
* Client side rate limiting
*/
rate_limiting?: {
/**
* The average number of events per second that should be permitted
*
* @default 10
*/
events_per_second?: number
/**
* How many events can be captured in a burst. This defaults to 10 times the events_per_second count
*
* @default 10 * `events_per_second`
*/
events_burst_limit?: number
}
/**
* Used when sending data via `fetch`, use with care.
* This is intentionally meant to be used with NextJS `fetch`
*
* Incorrect `cache` usage may cause out-of-date data for feature flags, actions tracking, etc.
* See https://nextjs.org/docs/app/api-reference/functions/fetch#fetchurl-options
*/
fetch_options?: {
cache?: RequestInit['cache']
next_options?: NextOptions
}
/**
* Used to change the behavior of the request queue.
* This is an advanced feature and should be used with caution.
*/
request_queue_config?: RequestQueueConfig
// ------- PREVIEW CONFIGS -------
/**
* PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION
* Whether to wrap fetch and add tracing headers to the request
* */
__add_tracing_headers?: boolean
/**
* PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION
* Enables the new RemoteConfig approach to loading config instead of decide
* */
__preview_remote_config?: boolean
/**
* PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION
* Whether to send a sentinel value for distinct id, device id, and session id, which will be replaced server-side by a cookieless hash
* */
__preview_experimental_cookieless_mode?: boolean
/**
* PREVIEW - MAY CHANGE WITHOUT WARNING - DO NOT USE IN PRODUCTION
* Whether to use the new /flags/ endpoint
* */
__preview_flags_v2?: boolean
// ------- RETIRED CONFIGS - NO REPLACEMENT OR USAGE -------
/** @deprecated - NOT USED ANYMORE, kept here for backwards compatibility reasons */
api_method?: string
/** @deprecated - NOT USED ANYMORE, kept here for backwards compatibility reasons */
inapp_protocol?: string
/** @deprecated - NOT USED ANYMORE, kept here for backwards compatibility reasons */
inapp_link_new_window?: boolean
}
export interface SessionRecordingOptions {
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
* @default 'ph-no-capture'
*/
blockClass?: string | RegExp
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
* @default null
*/
blockSelector?: string | null
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
* @default 'ph-ignore-input'
*/
ignoreClass?: string | RegExp
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
* @default 'ph-mask'
*/
maskTextClass?: string | RegExp
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
*/
maskTextSelector?: string | null
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
*/
maskTextFn?: ((text: string, element?: HTMLElement) => string) | null
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
*/
maskAllInputs?: boolean
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
*/
maskInputOptions?: recordOptions['maskInputOptions']
/**
* Derived from `rrweb.record` options
* @see https://github.com/rrweb-io/rrweb/blob/master/guide.md
*/
maskInputFn?: ((text: string, element?: HTMLElement) => string) | null
/**