MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / constructor

Method constructor

packages/sdks/web/src/index.ts:75–135  ·  view source on GitHub ↗
(public options: OpenPanelOptions)

Source from the content-addressed store, hash-verified

73 private pendingRevenues: PendingRevenue[] = [];
74
75 constructor(public options: OpenPanelOptions) {
76 super({
77 sdk: 'web',
78 sdkVersion: process.env.WEB_VERSION!,
79 ...options,
80 });
81
82 if (!this.isServer()) {
83 try {
84 const pending = sessionStorage.getItem('openpanel-pending-revenues');
85 if (pending) {
86 const parsed = JSON.parse(pending);
87 if (Array.isArray(parsed)) {
88 this.pendingRevenues = parsed;
89 }
90 }
91 } catch {
92 this.pendingRevenues = [];
93 }
94
95 this.setGlobalProperties({
96 __referrer: document.referrer,
97 });
98
99 if (this.options.trackScreenViews) {
100 this.trackScreenViews();
101 setTimeout(() => this.screenView(), 0);
102 }
103
104 if (this.options.trackOutgoingLinks) {
105 this.trackOutgoingLinks();
106 }
107
108 if (this.options.trackAttributes) {
109 this.trackAttributes();
110 }
111
112 if (this.options.sessionReplay?.enabled) {
113 const sampleRate = this.options.sessionReplay.sampleRate ?? 1;
114 const sampled = Math.random() < sampleRate;
115 if (sampled) {
116 this.loadReplayModule().then((mod) => {
117 if (!mod) {
118 return;
119 }
120 mod.startReplayRecorder(this.options.sessionReplay!, (chunk) => {
121 // Replay chunks go through send() and are queued when disabled or waitForProfile
122 // until ready() is called (base SDK also queues replay until sessionId is set).
123 this.send({
124 type: 'replay',
125 payload: {
126 ...chunk,
127 sessionId: this.sessionId,
128 },
129 });
130 });
131 });
132 }

Callers

nothing calls this directly

Calls 11

isServerMethod · 0.95
setGlobalPropertiesMethod · 0.95
trackScreenViewsMethod · 0.95
screenViewMethod · 0.95
trackOutgoingLinksMethod · 0.95
trackAttributesMethod · 0.95
loadReplayModuleMethod · 0.95
sendMethod · 0.95
getItemMethod · 0.80
parseMethod · 0.80
thenMethod · 0.45

Tested by

no test coverage detected