@growth-rail/core 1.0.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/dist/index.d.mts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +876 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +848 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +40 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,848 @@
|
|
|
1
|
+
// src/api.ts
|
|
2
|
+
var APIClient = class {
|
|
3
|
+
baseUrl;
|
|
4
|
+
apiKey;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
const envBaseUrl = typeof process !== "undefined" && process.env?.ENV_BASE_URL;
|
|
7
|
+
this.baseUrl = envBaseUrl || "http://hw84ko0ok4ccws4sws8gos0o.193.31.30.10.sslip.io";
|
|
8
|
+
this.apiKey = options.apiKey;
|
|
9
|
+
}
|
|
10
|
+
async request(endpoint, method, body) {
|
|
11
|
+
const headers = {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"X-GrowthRail-ProjectSecret": this.apiKey
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
17
|
+
method,
|
|
18
|
+
headers,
|
|
19
|
+
body: body ? JSON.stringify(body) : void 0
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(`GrowthRail API Error: ${response.statusText}`);
|
|
23
|
+
}
|
|
24
|
+
return response.json();
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error("GrowthRail SDK Error:", error);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async getNewUserExperience() {
|
|
31
|
+
return this.request("/api/v1/sdk/new-user-experience", "POST");
|
|
32
|
+
}
|
|
33
|
+
async initAppUser(clientProvidedId) {
|
|
34
|
+
return this.request("/api/v1/sdk/init-app-user", "POST", { clientProvidedId });
|
|
35
|
+
}
|
|
36
|
+
async createReferralLink(referrerId, rewardEventName) {
|
|
37
|
+
return this.request("/api/v1/sdk/create-referral-link", "POST", {
|
|
38
|
+
referrerId,
|
|
39
|
+
rewardEventName
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async trackReferral(referralCode, rewardEventName) {
|
|
43
|
+
return this.request("/api/v1/sdk/track-referral", "POST", {
|
|
44
|
+
referralCode,
|
|
45
|
+
rewardEventName
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async trackRewardEvent(refereeId, referralTrackingId, eventName) {
|
|
49
|
+
return this.request("/api/v1/sdk/track-reward-event", "POST", {
|
|
50
|
+
refereeId,
|
|
51
|
+
referralTrackingId,
|
|
52
|
+
eventName
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/storage.ts
|
|
58
|
+
var StorageManager = class _StorageManager {
|
|
59
|
+
static REFERRAL_CODE_KEY = "gr_ref_code";
|
|
60
|
+
static TRACKED_REFERRAL_KEY = "gr_tracked_referral";
|
|
61
|
+
options = {};
|
|
62
|
+
constructor(options) {
|
|
63
|
+
if (options) {
|
|
64
|
+
this.options = options;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Helper to set a cookie
|
|
68
|
+
setCookie(name, value, days = 30) {
|
|
69
|
+
if (typeof document === "undefined") return;
|
|
70
|
+
let expires = "";
|
|
71
|
+
if (days) {
|
|
72
|
+
const date = /* @__PURE__ */ new Date();
|
|
73
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
|
|
74
|
+
expires = `; expires=${date.toUTCString()}`;
|
|
75
|
+
}
|
|
76
|
+
let domain = "";
|
|
77
|
+
if (this.options.cookieDomain) {
|
|
78
|
+
domain = `; domain=${this.options.cookieDomain}`;
|
|
79
|
+
}
|
|
80
|
+
document.cookie = `${name}=${value || ""}${expires}${domain}; path=/; SameSite=Lax`;
|
|
81
|
+
}
|
|
82
|
+
// Helper to get a cookie
|
|
83
|
+
getCookie(name) {
|
|
84
|
+
if (typeof document === "undefined") return null;
|
|
85
|
+
const nameEQ = `${name}=`;
|
|
86
|
+
const ca = document.cookie.split(";");
|
|
87
|
+
for (let i = 0; i < ca.length; i++) {
|
|
88
|
+
let c = ca[i];
|
|
89
|
+
while (c.charAt(0) === " ") c = c.substring(1, c.length);
|
|
90
|
+
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
getReferralCode() {
|
|
95
|
+
return this.getCookie(_StorageManager.REFERRAL_CODE_KEY);
|
|
96
|
+
}
|
|
97
|
+
setReferralCode(code) {
|
|
98
|
+
this.setCookie(_StorageManager.REFERRAL_CODE_KEY, code, 30);
|
|
99
|
+
}
|
|
100
|
+
setTrackedReferral(trackingId) {
|
|
101
|
+
this.setCookie(_StorageManager.TRACKED_REFERRAL_KEY, trackingId, 30);
|
|
102
|
+
}
|
|
103
|
+
getTrackedReferral() {
|
|
104
|
+
return this.getCookie(_StorageManager.TRACKED_REFERRAL_KEY);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/referral-modal.ts
|
|
109
|
+
var ReferralModal = class {
|
|
110
|
+
referrerExperience;
|
|
111
|
+
deps;
|
|
112
|
+
host = null;
|
|
113
|
+
shadow = null;
|
|
114
|
+
overlay = null;
|
|
115
|
+
content = null;
|
|
116
|
+
constructor(deps, referrerExperience) {
|
|
117
|
+
this.deps = deps;
|
|
118
|
+
this.referrerExperience = referrerExperience;
|
|
119
|
+
}
|
|
120
|
+
show(options, container) {
|
|
121
|
+
if (this.host) return;
|
|
122
|
+
this.createDom(options, container);
|
|
123
|
+
this.bindEvents();
|
|
124
|
+
if (!container) {
|
|
125
|
+
document.body.style.overflow = "hidden";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
hide() {
|
|
129
|
+
if (!this.host) return;
|
|
130
|
+
if (this.host && this.host.parentNode) {
|
|
131
|
+
this.host.parentNode.removeChild(this.host);
|
|
132
|
+
}
|
|
133
|
+
this.host = null;
|
|
134
|
+
this.overlay = null;
|
|
135
|
+
this.content = null;
|
|
136
|
+
this.shadow = null;
|
|
137
|
+
document.body.style.overflow = "";
|
|
138
|
+
}
|
|
139
|
+
createDom(options, container) {
|
|
140
|
+
const resolvedOptions = {
|
|
141
|
+
...this.referrerExperience,
|
|
142
|
+
...options ?? {}
|
|
143
|
+
};
|
|
144
|
+
const baseTheme = this.getTheme();
|
|
145
|
+
const theme = {
|
|
146
|
+
...baseTheme,
|
|
147
|
+
colorPrimary: resolvedOptions.modal?.theme?.primaryColor || baseTheme.colorPrimary,
|
|
148
|
+
colorBackground: resolvedOptions.modal?.theme?.backgroundColor || baseTheme.colorBackground,
|
|
149
|
+
colorTint: resolvedOptions.modal?.theme?.tintColor || baseTheme.colorTint
|
|
150
|
+
};
|
|
151
|
+
const isEmbedded = !!container;
|
|
152
|
+
this.host = document.createElement("div");
|
|
153
|
+
this.host.style.all = "initial";
|
|
154
|
+
if (!isEmbedded) {
|
|
155
|
+
this.host.style.position = "absolute";
|
|
156
|
+
this.host.style.zIndex = "2147483647";
|
|
157
|
+
} else {
|
|
158
|
+
this.host.style.display = "block";
|
|
159
|
+
this.host.style.width = "100%";
|
|
160
|
+
this.host.style.height = "100%";
|
|
161
|
+
}
|
|
162
|
+
this.host.id = "growth-rail-modal-host";
|
|
163
|
+
this.host.style.setProperty("--gr-primary", theme.colorPrimary);
|
|
164
|
+
this.host.style.setProperty("--gr-text", theme.colorText);
|
|
165
|
+
this.host.style.setProperty("--gr-text-secondary", theme.colorTextSecondary);
|
|
166
|
+
this.host.style.setProperty("--gr-bg", theme.colorBackground);
|
|
167
|
+
this.host.style.setProperty("--gr-tint", theme.colorTint);
|
|
168
|
+
this.host.style.setProperty("--gr-surface", theme.colorSurface);
|
|
169
|
+
this.host.style.setProperty("--gr-border", theme.colorBorder);
|
|
170
|
+
this.host.style.setProperty("--gr-error", theme.colorError);
|
|
171
|
+
this.host.style.setProperty("--gr-radius", theme.borderRadius);
|
|
172
|
+
this.host.style.setProperty("--gr-font", 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif');
|
|
173
|
+
this.shadow = this.host.attachShadow({ mode: "open" });
|
|
174
|
+
const style = document.createElement("style");
|
|
175
|
+
style.textContent = `
|
|
176
|
+
:host { all: initial; display: block; }
|
|
177
|
+
* { box-sizing: border-box; }
|
|
178
|
+
|
|
179
|
+
@keyframes gr-fade-in { from { opacity: 0; } to { opacity: 1; } }
|
|
180
|
+
@keyframes gr-slide-up { from { opacity: 0; transform: translateY(20px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
|
|
181
|
+
@keyframes gr-slide-in-right { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
|
|
182
|
+
@keyframes gr-slide-in-left { from { opacity: 0; transform: translateX(-100%); } to { opacity: 1; transform: translateX(0); } }
|
|
183
|
+
|
|
184
|
+
.gr-overlay {
|
|
185
|
+
position: fixed;
|
|
186
|
+
top: 0; left: 0; width: 100vw; height: 100vh;
|
|
187
|
+
display: flex;
|
|
188
|
+
z-index: 2147483647;
|
|
189
|
+
font-family: var(--gr-font);
|
|
190
|
+
animation: gr-fade-in 0.2s ease-out forwards;
|
|
191
|
+
backdrop-filter: blur(4px);
|
|
192
|
+
}
|
|
193
|
+
.gr-overlay--modal {
|
|
194
|
+
background-color: var(--gr-tint);
|
|
195
|
+
align-items: center;
|
|
196
|
+
justify-content: center;
|
|
197
|
+
}
|
|
198
|
+
.gr-overlay--drawer {
|
|
199
|
+
background-color: var(--gr-tint);
|
|
200
|
+
align-items: flex-start;
|
|
201
|
+
justify-content: flex-start;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.gr-container {
|
|
205
|
+
position: relative;
|
|
206
|
+
background-color: var(--gr-bg);
|
|
207
|
+
color: var(--gr-text);
|
|
208
|
+
padding: 32px;
|
|
209
|
+
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* Embedded Variant */
|
|
213
|
+
.gr-container--embedded {
|
|
214
|
+
width: 100%;
|
|
215
|
+
height: 100%;
|
|
216
|
+
box-shadow: none;
|
|
217
|
+
border: 1px solid var(--gr-border);
|
|
218
|
+
border-radius: var(--gr-radius);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* Modal Variant */
|
|
222
|
+
.gr-container--modal {
|
|
223
|
+
width: 90%;
|
|
224
|
+
max-width: 480px;
|
|
225
|
+
border-radius: var(--gr-radius);
|
|
226
|
+
animation: gr-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/* Drawer Variant */
|
|
230
|
+
.gr-container--drawer {
|
|
231
|
+
position: absolute;
|
|
232
|
+
width: 400px;
|
|
233
|
+
max-width: calc(100vw - 20px);
|
|
234
|
+
max-height: calc(100vh - 40px);
|
|
235
|
+
overflow-y: auto;
|
|
236
|
+
}
|
|
237
|
+
.gr-container--right {
|
|
238
|
+
right: 0;
|
|
239
|
+
border-top-left-radius: var(--gr-radius);
|
|
240
|
+
border-bottom-left-radius: var(--gr-radius);
|
|
241
|
+
animation: gr-slide-in-right 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
242
|
+
}
|
|
243
|
+
.gr-container--left {
|
|
244
|
+
left: 0;
|
|
245
|
+
border-top-right-radius: var(--gr-radius);
|
|
246
|
+
border-bottom-right-radius: var(--gr-radius);
|
|
247
|
+
animation: gr-slide-in-left 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
248
|
+
}
|
|
249
|
+
.gr-container--top { top: 100px; }
|
|
250
|
+
.gr-container--bottom { bottom: 100px; }
|
|
251
|
+
|
|
252
|
+
.gr-close-btn {
|
|
253
|
+
position: absolute; top: 20px; right: 20px;
|
|
254
|
+
background: transparent; border: none; cursor: pointer;
|
|
255
|
+
color: #9ca3af; padding: 4px; border-radius: 50%;
|
|
256
|
+
display: flex; alignItems: center; justifyContent: center;
|
|
257
|
+
transition: all 0.2s;
|
|
258
|
+
}
|
|
259
|
+
.gr-close-btn:hover { background-color: var(--gr-surface); color: var(--gr-text); }
|
|
260
|
+
|
|
261
|
+
.gr-header { text-align: center; margin-bottom: 28px; }
|
|
262
|
+
.gr-icon-lg { font-size: 32px; margin-bottom: 12px; }
|
|
263
|
+
|
|
264
|
+
.gr-title {
|
|
265
|
+
margin: 0 0 8px 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em;
|
|
266
|
+
}
|
|
267
|
+
.gr-subtitle {
|
|
268
|
+
margin: 0; font-size: 14px; line-height: 1.5; color: var(--gr-text-secondary);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.gr-loading {
|
|
272
|
+
padding: 16px; background-color: var(--gr-surface); border-radius: 8px;
|
|
273
|
+
text-align: center; color: var(--gr-text-secondary); font-size: 14px;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.gr-label {
|
|
277
|
+
display: block; font-size: 12px; font-weight: 600;
|
|
278
|
+
color: var(--gr-text-secondary); margin-bottom: 8px;
|
|
279
|
+
text-transform: uppercase; letter-spacing: 0.05em;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.gr-share-label {
|
|
283
|
+
text-align: center; margin-bottom: 16px; font-size: 13px; font-weight: 500;
|
|
284
|
+
color: var(--gr-text-secondary); display: flex; align-items: center; gap: 12px;
|
|
285
|
+
}
|
|
286
|
+
.gr-divider { flex: 1; height: 1px; background: var(--gr-border); }
|
|
287
|
+
|
|
288
|
+
.gr-social-container {
|
|
289
|
+
display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.gr-btn {
|
|
293
|
+
padding: 14px;
|
|
294
|
+
font-size: 15px;
|
|
295
|
+
font-weight: 600;
|
|
296
|
+
background-color: var(--gr-primary);
|
|
297
|
+
color: #ffffff;
|
|
298
|
+
border: none;
|
|
299
|
+
border-radius: var(--gr-radius);
|
|
300
|
+
cursor: pointer;
|
|
301
|
+
transition: all 0.2s ease;
|
|
302
|
+
text-align: center;
|
|
303
|
+
width: 100%;
|
|
304
|
+
display: block;
|
|
305
|
+
}
|
|
306
|
+
.gr-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
|
|
307
|
+
.gr-btn:active { transform: translateY(0); filter: brightness(0.95); }
|
|
308
|
+
.gr-btn:disabled { opacity: 0.7; cursor: not-allowed; }
|
|
309
|
+
|
|
310
|
+
.gr-btn--sm {
|
|
311
|
+
padding: 8px 16px;
|
|
312
|
+
font-size: 13px;
|
|
313
|
+
width: auto;
|
|
314
|
+
border-radius: calc(var(--gr-radius) - 4px);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.gr-input-group {
|
|
318
|
+
display: flex;
|
|
319
|
+
align-items: center;
|
|
320
|
+
background-color: var(--gr-surface);
|
|
321
|
+
border: 1px solid var(--gr-border);
|
|
322
|
+
border-radius: var(--gr-radius);
|
|
323
|
+
padding: 4px;
|
|
324
|
+
margin-bottom: 24px;
|
|
325
|
+
}
|
|
326
|
+
.gr-input-group:focus-within {
|
|
327
|
+
border-color: var(--gr-primary);
|
|
328
|
+
box-shadow: 0 0 0 3px var(--gr-surface);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.gr-input {
|
|
332
|
+
flex: 1;
|
|
333
|
+
padding: 10px 12px;
|
|
334
|
+
font-size: 14px;
|
|
335
|
+
border: none;
|
|
336
|
+
background: transparent;
|
|
337
|
+
color: var(--gr-text);
|
|
338
|
+
outline: none;
|
|
339
|
+
font-family: monospace;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.gr-social-btn {
|
|
343
|
+
display: flex; align-items: center; justify-content: center;
|
|
344
|
+
width: 42px; height: 42px;
|
|
345
|
+
border-radius: 50%;
|
|
346
|
+
background-color: var(--gr-surface);
|
|
347
|
+
color: var(--gr-text-secondary);
|
|
348
|
+
border: 1px solid var(--gr-border);
|
|
349
|
+
transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
350
|
+
cursor: pointer;
|
|
351
|
+
}
|
|
352
|
+
.gr-social-btn:hover { transform: scale(1.15) rotate(3deg); color: #fff; }
|
|
353
|
+
|
|
354
|
+
.gr-powered-by {
|
|
355
|
+
margin-top: 24px;
|
|
356
|
+
text-align: center;
|
|
357
|
+
font-size: 11px;
|
|
358
|
+
color: #9ca3af;
|
|
359
|
+
display: flex;
|
|
360
|
+
align-items: center;
|
|
361
|
+
justify-content: center;
|
|
362
|
+
gap: 4px;
|
|
363
|
+
opacity: 0.8;
|
|
364
|
+
}
|
|
365
|
+
.gr-powered-by a {
|
|
366
|
+
color: inherit;
|
|
367
|
+
text-decoration: none;
|
|
368
|
+
font-weight: 600;
|
|
369
|
+
transition: opacity 0.2s;
|
|
370
|
+
}
|
|
371
|
+
.gr-powered-by a:hover { opacity: 1; text-decoration: underline; }
|
|
372
|
+
`;
|
|
373
|
+
this.shadow.appendChild(style);
|
|
374
|
+
this.content = document.createElement("div");
|
|
375
|
+
const isDrawer = resolvedOptions.modal.type === "drawer";
|
|
376
|
+
const position = resolvedOptions.trigger.position || "top-right";
|
|
377
|
+
const contentClasses = ["gr-container"];
|
|
378
|
+
if (isEmbedded) {
|
|
379
|
+
contentClasses.push("gr-container--embedded");
|
|
380
|
+
this.content.className = contentClasses.join(" ");
|
|
381
|
+
this.renderInternalContent(theme, options, isEmbedded);
|
|
382
|
+
this.shadow.appendChild(this.content);
|
|
383
|
+
if (container) {
|
|
384
|
+
container.appendChild(this.host);
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
this.overlay = document.createElement("div");
|
|
388
|
+
this.overlay.className = `gr-overlay ${isDrawer ? "gr-overlay--drawer" : "gr-overlay--modal"}`;
|
|
389
|
+
if (isDrawer) {
|
|
390
|
+
contentClasses.push("gr-container--drawer");
|
|
391
|
+
if (position.includes("right")) contentClasses.push("gr-container--right");
|
|
392
|
+
else contentClasses.push("gr-container--left");
|
|
393
|
+
if (position.includes("bottom")) contentClasses.push("gr-container--bottom");
|
|
394
|
+
else contentClasses.push("gr-container--top");
|
|
395
|
+
} else {
|
|
396
|
+
contentClasses.push("gr-container--modal");
|
|
397
|
+
}
|
|
398
|
+
this.content.className = contentClasses.join(" ");
|
|
399
|
+
this.renderInternalContent(theme, options, isEmbedded);
|
|
400
|
+
this.overlay.appendChild(this.content);
|
|
401
|
+
this.shadow.appendChild(this.overlay);
|
|
402
|
+
document.body.appendChild(this.host);
|
|
403
|
+
this.overlay.onclick = (e) => {
|
|
404
|
+
if (e.target === this.overlay) this.hide();
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
getTheme() {
|
|
409
|
+
return {
|
|
410
|
+
colorPrimary: "#2563eb",
|
|
411
|
+
colorText: "#111827",
|
|
412
|
+
colorTextSecondary: "#6b7280",
|
|
413
|
+
colorBackground: "#ffffff",
|
|
414
|
+
colorTint: "#f9fafb",
|
|
415
|
+
colorSurface: "#f9fafb",
|
|
416
|
+
colorBorder: "#e5e7eb",
|
|
417
|
+
colorError: "#ef4444",
|
|
418
|
+
borderRadius: "16px"
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
async renderInternalContent(theme, options, isEmbedded = false) {
|
|
422
|
+
if (!this.content) return;
|
|
423
|
+
this.content.innerHTML = "";
|
|
424
|
+
if (!isEmbedded) {
|
|
425
|
+
const closeBtn = document.createElement("button");
|
|
426
|
+
closeBtn.className = "gr-close-btn";
|
|
427
|
+
closeBtn.innerHTML = `
|
|
428
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
429
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
430
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
431
|
+
</svg>
|
|
432
|
+
`;
|
|
433
|
+
closeBtn.onclick = () => this.hide();
|
|
434
|
+
this.content.appendChild(closeBtn);
|
|
435
|
+
}
|
|
436
|
+
const header = document.createElement("div");
|
|
437
|
+
header.className = "gr-header";
|
|
438
|
+
const icon = document.createElement("div");
|
|
439
|
+
icon.className = "gr-icon-lg";
|
|
440
|
+
icon.innerHTML = "\u{1F381}";
|
|
441
|
+
header.appendChild(icon);
|
|
442
|
+
const title = document.createElement("h3");
|
|
443
|
+
title.className = "gr-title";
|
|
444
|
+
title.textContent = options?.title ?? this.referrerExperience.modal.title ?? "Invite Friends & Earn";
|
|
445
|
+
header.appendChild(title);
|
|
446
|
+
const subtitle = document.createElement("p");
|
|
447
|
+
subtitle.className = "gr-subtitle";
|
|
448
|
+
subtitle.textContent = "Share your unique link and earn rewards for every friend who signs up.";
|
|
449
|
+
header.appendChild(subtitle);
|
|
450
|
+
this.content.appendChild(header);
|
|
451
|
+
if (!this.deps.isUserReady()) {
|
|
452
|
+
const msg = document.createElement("div");
|
|
453
|
+
msg.className = "gr-loading";
|
|
454
|
+
msg.textContent = "Please log in to view your referral dashboard.";
|
|
455
|
+
this.content.appendChild(msg);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
let referralLink = this.deps.getReferralLink();
|
|
459
|
+
const actionContainer = document.createElement("div");
|
|
460
|
+
this.renderLinkView(actionContainer, referralLink, theme);
|
|
461
|
+
this.content.appendChild(actionContainer);
|
|
462
|
+
if (referralLink) {
|
|
463
|
+
this.renderSocialShare(this.content, referralLink, theme);
|
|
464
|
+
}
|
|
465
|
+
const poweredBy = document.createElement("div");
|
|
466
|
+
poweredBy.className = "gr-powered-by";
|
|
467
|
+
poweredBy.innerHTML = `
|
|
468
|
+
Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
|
|
469
|
+
`;
|
|
470
|
+
this.content.appendChild(poweredBy);
|
|
471
|
+
}
|
|
472
|
+
renderLinkView(container, link, theme) {
|
|
473
|
+
const label = document.createElement("label");
|
|
474
|
+
label.className = "gr-label";
|
|
475
|
+
label.textContent = "Your unique link";
|
|
476
|
+
container.appendChild(label);
|
|
477
|
+
const linkGroup = document.createElement("div");
|
|
478
|
+
linkGroup.className = "gr-input-group";
|
|
479
|
+
const input = document.createElement("input");
|
|
480
|
+
input.className = "gr-input";
|
|
481
|
+
input.type = "text";
|
|
482
|
+
input.value = link;
|
|
483
|
+
input.readOnly = true;
|
|
484
|
+
const copyBtn = document.createElement("button");
|
|
485
|
+
copyBtn.className = "gr-btn gr-btn--sm";
|
|
486
|
+
copyBtn.textContent = "Copy";
|
|
487
|
+
copyBtn.onclick = async () => {
|
|
488
|
+
try {
|
|
489
|
+
await navigator.clipboard.writeText(link);
|
|
490
|
+
const originalText = copyBtn.textContent;
|
|
491
|
+
copyBtn.textContent = "Copied!";
|
|
492
|
+
copyBtn.style.backgroundColor = "#10b981";
|
|
493
|
+
setTimeout(() => {
|
|
494
|
+
copyBtn.textContent = originalText;
|
|
495
|
+
copyBtn.style.backgroundColor = "";
|
|
496
|
+
}, 2e3);
|
|
497
|
+
} catch (err) {
|
|
498
|
+
console.error("Failed to copy", err);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
linkGroup.appendChild(input);
|
|
502
|
+
linkGroup.appendChild(copyBtn);
|
|
503
|
+
container.appendChild(linkGroup);
|
|
504
|
+
}
|
|
505
|
+
renderSocialShare(container, link, theme) {
|
|
506
|
+
const shareContainer = document.createElement("div");
|
|
507
|
+
const label = document.createElement("div");
|
|
508
|
+
label.className = "gr-share-label";
|
|
509
|
+
label.innerHTML = `<span class="gr-divider"></span>Share via<span class="gr-divider"></span>`;
|
|
510
|
+
shareContainer.appendChild(label);
|
|
511
|
+
const buttonsContainer = document.createElement("div");
|
|
512
|
+
buttonsContainer.className = "gr-social-container";
|
|
513
|
+
const platforms = [
|
|
514
|
+
{ name: "Twitter", color: "#000000", icon: '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>', url: `https://twitter.com/intent/tweet?url=${encodeURIComponent(link)}&text=Check+this+out!` },
|
|
515
|
+
{ name: "Facebook", color: "#1877F2", icon: '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036c-2.648 0-2.928 1.67-2.928 3.403v1.596h3.949l-.577 3.667h-3.372v7.98h-4.938z"/></svg>', url: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(link)}` },
|
|
516
|
+
{ name: "LinkedIn", color: "#0A66C2", icon: '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>', url: `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(link)}` },
|
|
517
|
+
{ name: "WhatsApp", color: "#25D366", icon: '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>', url: `https://api.whatsapp.com/send?text=${encodeURIComponent(link)}` },
|
|
518
|
+
{ name: "Email", color: "#888888", icon: '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/></svg>', url: `mailto:?subject=Check this out&body=${encodeURIComponent(link)}` }
|
|
519
|
+
];
|
|
520
|
+
platforms.forEach((p) => {
|
|
521
|
+
const btn = document.createElement("a");
|
|
522
|
+
btn.href = p.url;
|
|
523
|
+
btn.target = "_blank";
|
|
524
|
+
btn.rel = "noopener noreferrer";
|
|
525
|
+
btn.className = "gr-social-btn";
|
|
526
|
+
btn.innerHTML = p.icon;
|
|
527
|
+
btn.title = `Share on ${p.name}`;
|
|
528
|
+
btn.onmouseenter = () => {
|
|
529
|
+
btn.style.backgroundColor = p.color;
|
|
530
|
+
btn.style.color = "#ffffff";
|
|
531
|
+
btn.style.borderColor = p.color;
|
|
532
|
+
};
|
|
533
|
+
btn.onmouseleave = () => {
|
|
534
|
+
btn.style.backgroundColor = "";
|
|
535
|
+
btn.style.color = "";
|
|
536
|
+
btn.style.borderColor = "";
|
|
537
|
+
};
|
|
538
|
+
buttonsContainer.appendChild(btn);
|
|
539
|
+
});
|
|
540
|
+
shareContainer.appendChild(buttonsContainer);
|
|
541
|
+
container.appendChild(shareContainer);
|
|
542
|
+
}
|
|
543
|
+
bindEvents() {
|
|
544
|
+
if (this.overlay) {
|
|
545
|
+
this.overlay.onclick = (e) => {
|
|
546
|
+
if (e.target === this.overlay) {
|
|
547
|
+
this.hide();
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// src/trigger-button.ts
|
|
555
|
+
var TriggerButton = class {
|
|
556
|
+
options;
|
|
557
|
+
host = null;
|
|
558
|
+
shadow = null;
|
|
559
|
+
element = null;
|
|
560
|
+
constructor(options) {
|
|
561
|
+
this.options = options;
|
|
562
|
+
}
|
|
563
|
+
mount() {
|
|
564
|
+
if (this.host) return;
|
|
565
|
+
this.createDom();
|
|
566
|
+
}
|
|
567
|
+
unmount() {
|
|
568
|
+
if (this.host && this.host.parentNode) {
|
|
569
|
+
document.body.removeChild(this.host);
|
|
570
|
+
}
|
|
571
|
+
this.host = null;
|
|
572
|
+
this.shadow = null;
|
|
573
|
+
this.element = null;
|
|
574
|
+
}
|
|
575
|
+
createDom() {
|
|
576
|
+
this.host = document.createElement("div");
|
|
577
|
+
this.host.style.all = "initial";
|
|
578
|
+
this.host.style.position = "absolute";
|
|
579
|
+
this.host.style.zIndex = "2147483646";
|
|
580
|
+
const offset = { x: 0, y: 100 };
|
|
581
|
+
this.host.style.setProperty("--gr-offset-y", `${offset.y}px`);
|
|
582
|
+
this.shadow = this.host.attachShadow({ mode: "open" });
|
|
583
|
+
const style = document.createElement("style");
|
|
584
|
+
style.textContent = `
|
|
585
|
+
:host {
|
|
586
|
+
all: initial;
|
|
587
|
+
display: block;
|
|
588
|
+
}
|
|
589
|
+
@keyframes gr-shimmer {
|
|
590
|
+
0% { transform: translateX(-150%) skewX(-15deg); }
|
|
591
|
+
50% { transform: translateX(150%) skewX(-15deg); }
|
|
592
|
+
100% { transform: translateX(150%) skewX(-15deg); }
|
|
593
|
+
}
|
|
594
|
+
.gr-floating-btn {
|
|
595
|
+
position: fixed;
|
|
596
|
+
width: 50px;
|
|
597
|
+
height: 50px;
|
|
598
|
+
background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
|
|
599
|
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
|
600
|
+
cursor: pointer;
|
|
601
|
+
z-index: 2147483646;
|
|
602
|
+
display: flex;
|
|
603
|
+
align-items: center;
|
|
604
|
+
justify-content: center;
|
|
605
|
+
transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, width 0.2s;
|
|
606
|
+
overflow: hidden;
|
|
607
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
608
|
+
box-sizing: border-box;
|
|
609
|
+
}
|
|
610
|
+
.gr-floating-btn * {
|
|
611
|
+
box-sizing: border-box;
|
|
612
|
+
}
|
|
613
|
+
.gr-floating-btn:hover {
|
|
614
|
+
transform: scale(1.05);
|
|
615
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
616
|
+
}
|
|
617
|
+
.gr-floating-btn--right {
|
|
618
|
+
right: 0;
|
|
619
|
+
border-top-left-radius: 8px;
|
|
620
|
+
border-bottom-left-radius: 8px;
|
|
621
|
+
border-top-right-radius: 0;
|
|
622
|
+
border-bottom-right-radius: 0;
|
|
623
|
+
padding-left: 4px; /* Optical balance */
|
|
624
|
+
}
|
|
625
|
+
.gr-floating-btn--left {
|
|
626
|
+
left: 0;
|
|
627
|
+
border-top-right-radius: 8px;
|
|
628
|
+
border-bottom-right-radius: 8px;
|
|
629
|
+
border-top-left-radius: 0;
|
|
630
|
+
border-bottom-left-radius: 0;
|
|
631
|
+
padding-right: 4px;
|
|
632
|
+
}
|
|
633
|
+
.gr-floating-btn--bottom {
|
|
634
|
+
bottom: var(--gr-offset-y);
|
|
635
|
+
}
|
|
636
|
+
.gr-floating-btn--top {
|
|
637
|
+
top: var(--gr-offset-y);
|
|
638
|
+
}
|
|
639
|
+
.gr-floating-btn::after {
|
|
640
|
+
content: '';
|
|
641
|
+
position: absolute;
|
|
642
|
+
top: 0;
|
|
643
|
+
left: 0;
|
|
644
|
+
width: 100%;
|
|
645
|
+
height: 100%;
|
|
646
|
+
background: linear-gradient(to right, transparent 0%, rgba(255, 255, 255, 0.4) 50%, transparent 100%);
|
|
647
|
+
transform: translateX(-150%) skewX(-15deg);
|
|
648
|
+
animation: gr-shimmer 3s infinite;
|
|
649
|
+
}
|
|
650
|
+
.gr-icon {
|
|
651
|
+
color: white;
|
|
652
|
+
width: 24px;
|
|
653
|
+
height: 24px;
|
|
654
|
+
position: relative;
|
|
655
|
+
z-index: 10;
|
|
656
|
+
}
|
|
657
|
+
`;
|
|
658
|
+
this.shadow.appendChild(style);
|
|
659
|
+
this.element = document.createElement("div");
|
|
660
|
+
const position = this.options.position || "bottom-right";
|
|
661
|
+
const classes = ["gr-floating-btn"];
|
|
662
|
+
if (position.includes("right")) classes.push("gr-floating-btn--right");
|
|
663
|
+
else classes.push("gr-floating-btn--left");
|
|
664
|
+
if (position.includes("bottom")) classes.push("gr-floating-btn--bottom");
|
|
665
|
+
else classes.push("gr-floating-btn--top");
|
|
666
|
+
this.element.className = classes.join(" ");
|
|
667
|
+
this.element.innerHTML = `
|
|
668
|
+
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
669
|
+
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
670
|
+
<rect x="2" y="7" width="20" height="5"></rect>
|
|
671
|
+
<line x1="12" y1="22" x2="12" y2="7"></line>
|
|
672
|
+
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
673
|
+
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
674
|
+
</svg>
|
|
675
|
+
`;
|
|
676
|
+
this.element.onclick = () => {
|
|
677
|
+
GrowthRail.showReferralDashboard();
|
|
678
|
+
};
|
|
679
|
+
this.shadow.appendChild(this.element);
|
|
680
|
+
document.body.appendChild(this.host);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
// src/core.ts
|
|
685
|
+
var GrowthRail = class _GrowthRail {
|
|
686
|
+
static api;
|
|
687
|
+
static storage;
|
|
688
|
+
static options;
|
|
689
|
+
static currentUser = null;
|
|
690
|
+
static initialized = false;
|
|
691
|
+
static referralModal = null;
|
|
692
|
+
static floatingButton = null;
|
|
693
|
+
static experience = null;
|
|
694
|
+
static userReadyPromise = null;
|
|
695
|
+
static userReadyResolver = null;
|
|
696
|
+
constructor() {
|
|
697
|
+
}
|
|
698
|
+
static init(options) {
|
|
699
|
+
if (_GrowthRail.initialized) return;
|
|
700
|
+
_GrowthRail.options = options;
|
|
701
|
+
_GrowthRail.api = new APIClient(options);
|
|
702
|
+
_GrowthRail.storage = new StorageManager({ cookieDomain: options.cookieDomain });
|
|
703
|
+
_GrowthRail.initialized = true;
|
|
704
|
+
_GrowthRail.autoTrackReferral();
|
|
705
|
+
}
|
|
706
|
+
static isInitialized() {
|
|
707
|
+
return _GrowthRail.initialized;
|
|
708
|
+
}
|
|
709
|
+
static ensureInitialized() {
|
|
710
|
+
if (!_GrowthRail.initialized) {
|
|
711
|
+
throw new Error("GrowthRail.init() must be called before using the SDK");
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
static async loadReferrerExperience(experience) {
|
|
715
|
+
try {
|
|
716
|
+
_GrowthRail.createReferralModal(experience);
|
|
717
|
+
if (experience.trigger.show) {
|
|
718
|
+
_GrowthRail.createTriggerButton(experience.trigger);
|
|
719
|
+
}
|
|
720
|
+
} catch (error) {
|
|
721
|
+
console.error("GrowthRail: Failed to load referrer experience", error);
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
static createReferralModal(referrerExperience) {
|
|
726
|
+
_GrowthRail.referralModal = new ReferralModal({
|
|
727
|
+
isUserReady: () => _GrowthRail.isUserReady(),
|
|
728
|
+
getReferralLink: () => _GrowthRail.currentUser?.referralLink || ""
|
|
729
|
+
}, referrerExperience);
|
|
730
|
+
}
|
|
731
|
+
static async autoTrackReferral() {
|
|
732
|
+
if (typeof window === "undefined") return;
|
|
733
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
734
|
+
const refCode = urlParams.get("referralCode");
|
|
735
|
+
const refEventName = urlParams.get("rewardEventName");
|
|
736
|
+
if (refCode) {
|
|
737
|
+
const newUserExperience = await _GrowthRail.api.getNewUserExperience();
|
|
738
|
+
const trackingResult = await _GrowthRail.trackReferral(refCode, refEventName ?? void 0);
|
|
739
|
+
_GrowthRail.storage.setTrackedReferral(trackingResult.referralTrackingId);
|
|
740
|
+
trackingResult.promotionalText && newUserExperience.banner.show && _GrowthRail.createPromotionalBanner(trackingResult.promotionalText, newUserExperience);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
static async initAppUser(clientProvidedId) {
|
|
744
|
+
_GrowthRail.ensureInitialized();
|
|
745
|
+
const appUser = await _GrowthRail.api.initAppUser(clientProvidedId);
|
|
746
|
+
_GrowthRail.currentUser = { ...appUser, id: clientProvidedId };
|
|
747
|
+
_GrowthRail.experience = appUser.referrerExperience;
|
|
748
|
+
_GrowthRail.loadReferrerExperience(appUser.referrerExperience);
|
|
749
|
+
if (_GrowthRail.userReadyResolver) {
|
|
750
|
+
_GrowthRail.userReadyResolver(_GrowthRail.currentUser);
|
|
751
|
+
} else {
|
|
752
|
+
_GrowthRail.userReadyPromise = Promise.resolve(_GrowthRail.currentUser);
|
|
753
|
+
}
|
|
754
|
+
return appUser;
|
|
755
|
+
}
|
|
756
|
+
static async trackReferral(referralCode, rewardEventName) {
|
|
757
|
+
_GrowthRail.ensureInitialized();
|
|
758
|
+
return _GrowthRail.api.trackReferral(referralCode, rewardEventName);
|
|
759
|
+
}
|
|
760
|
+
static async trackRewardEvent(eventName) {
|
|
761
|
+
_GrowthRail.ensureInitialized();
|
|
762
|
+
const refereeId = _GrowthRail.currentUser?.id;
|
|
763
|
+
if (!refereeId) {
|
|
764
|
+
throw new Error("GrowthRail: User must be initialized before tracking a reward event.");
|
|
765
|
+
}
|
|
766
|
+
const referralTrackingId = _GrowthRail.storage.getTrackedReferral();
|
|
767
|
+
if (!referralTrackingId) {
|
|
768
|
+
throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");
|
|
769
|
+
}
|
|
770
|
+
return _GrowthRail.api.trackRewardEvent(refereeId, referralTrackingId, eventName);
|
|
771
|
+
}
|
|
772
|
+
static getReferralLink() {
|
|
773
|
+
if (!_GrowthRail.currentUser?.referralLink) {
|
|
774
|
+
throw new Error("GrowthRail: Referral Link not loaded or user not initialized");
|
|
775
|
+
}
|
|
776
|
+
return _GrowthRail.currentUser.referralLink;
|
|
777
|
+
}
|
|
778
|
+
static getReferralCode() {
|
|
779
|
+
return _GrowthRail.currentUser?.referralCode;
|
|
780
|
+
}
|
|
781
|
+
static getUserId() {
|
|
782
|
+
return _GrowthRail.currentUser?.id;
|
|
783
|
+
}
|
|
784
|
+
static isUserReady() {
|
|
785
|
+
return _GrowthRail.currentUser !== null;
|
|
786
|
+
}
|
|
787
|
+
static ensureUserReady() {
|
|
788
|
+
if (_GrowthRail.currentUser) {
|
|
789
|
+
return Promise.resolve(_GrowthRail.currentUser);
|
|
790
|
+
}
|
|
791
|
+
if (!_GrowthRail.userReadyPromise) {
|
|
792
|
+
_GrowthRail.userReadyPromise = new Promise((resolve) => {
|
|
793
|
+
_GrowthRail.userReadyResolver = resolve;
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
return _GrowthRail.userReadyPromise;
|
|
797
|
+
}
|
|
798
|
+
static async showReferralDashboard(options) {
|
|
799
|
+
_GrowthRail.ensureInitialized();
|
|
800
|
+
if (!_GrowthRail.experience) {
|
|
801
|
+
throw new Error("GrowthRail: Experience not loaded");
|
|
802
|
+
}
|
|
803
|
+
if (_GrowthRail.referralModal) {
|
|
804
|
+
_GrowthRail.referralModal.hide();
|
|
805
|
+
}
|
|
806
|
+
_GrowthRail.referralModal?.show(options);
|
|
807
|
+
}
|
|
808
|
+
static createPromotionalBanner(promotionalText, newUserExperience) {
|
|
809
|
+
if (typeof document === "undefined") return;
|
|
810
|
+
const banner = document.createElement("div");
|
|
811
|
+
banner.style.position = "fixed";
|
|
812
|
+
banner.style.top = newUserExperience.banner.position.split("-")[1] === "top" ? "0" : "auto";
|
|
813
|
+
banner.style.bottom = newUserExperience.banner.position.split("-")[1] === "bottom" ? "0" : "auto";
|
|
814
|
+
banner.style.left = newUserExperience.banner.position.split("-")[0] === "left" ? "0" : "auto";
|
|
815
|
+
banner.style.right = newUserExperience.banner.position.split("-")[0] === "right" ? "0" : "auto";
|
|
816
|
+
banner.style.width = "100%";
|
|
817
|
+
banner.style.margin = "auto";
|
|
818
|
+
banner.style.backgroundColor = "#f0f0f0";
|
|
819
|
+
banner.style.padding = "10px";
|
|
820
|
+
banner.style.textAlign = "center";
|
|
821
|
+
banner.style.zIndex = "10000";
|
|
822
|
+
banner.textContent = promotionalText;
|
|
823
|
+
document.body.appendChild(banner);
|
|
824
|
+
}
|
|
825
|
+
static createTriggerButton(options) {
|
|
826
|
+
if (typeof window === "undefined") return;
|
|
827
|
+
if (!_GrowthRail.experience) {
|
|
828
|
+
throw new Error("GrowthRail: Experience not loaded");
|
|
829
|
+
}
|
|
830
|
+
if (_GrowthRail.floatingButton) {
|
|
831
|
+
_GrowthRail.floatingButton.unmount();
|
|
832
|
+
}
|
|
833
|
+
const finalOptions = { ..._GrowthRail.experience?.trigger, ...options };
|
|
834
|
+
_GrowthRail.floatingButton = new TriggerButton(finalOptions);
|
|
835
|
+
_GrowthRail.floatingButton.mount();
|
|
836
|
+
}
|
|
837
|
+
static destroyTriggerButton() {
|
|
838
|
+
if (_GrowthRail.floatingButton) {
|
|
839
|
+
_GrowthRail.floatingButton.unmount();
|
|
840
|
+
_GrowthRail.floatingButton = null;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
export {
|
|
845
|
+
GrowthRail,
|
|
846
|
+
ReferralModal
|
|
847
|
+
};
|
|
848
|
+
//# sourceMappingURL=index.mjs.map
|