@growth-rail/core 1.0.0 → 2.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.js +4 -863
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -835
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,697 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
GrowthRail: () => GrowthRail,
|
|
24
|
-
ReferralModal: () => ReferralModal
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
|
-
// src/api.ts
|
|
29
|
-
var APIClient = class {
|
|
30
|
-
baseUrl;
|
|
31
|
-
apiKey;
|
|
32
|
-
constructor(options) {
|
|
33
|
-
const envBaseUrl = typeof process !== "undefined" && process.env?.ENV_BASE_URL;
|
|
34
|
-
this.baseUrl = envBaseUrl || "http://hw84ko0ok4ccws4sws8gos0o.193.31.30.10.sslip.io";
|
|
35
|
-
this.apiKey = options.apiKey;
|
|
36
|
-
}
|
|
37
|
-
async request(endpoint, method, body) {
|
|
38
|
-
const headers = {
|
|
39
|
-
"Content-Type": "application/json",
|
|
40
|
-
"X-GrowthRail-ProjectSecret": this.apiKey
|
|
41
|
-
};
|
|
42
|
-
try {
|
|
43
|
-
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
44
|
-
method,
|
|
45
|
-
headers,
|
|
46
|
-
body: body ? JSON.stringify(body) : void 0
|
|
47
|
-
});
|
|
48
|
-
if (!response.ok) {
|
|
49
|
-
throw new Error(`GrowthRail API Error: ${response.statusText}`);
|
|
50
|
-
}
|
|
51
|
-
return response.json();
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("GrowthRail SDK Error:", error);
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async getNewUserExperience() {
|
|
58
|
-
return this.request("/api/v1/sdk/new-user-experience", "POST");
|
|
59
|
-
}
|
|
60
|
-
async initAppUser(clientProvidedId) {
|
|
61
|
-
return this.request("/api/v1/sdk/init-app-user", "POST", { clientProvidedId });
|
|
62
|
-
}
|
|
63
|
-
async createReferralLink(referrerId, rewardEventName) {
|
|
64
|
-
return this.request("/api/v1/sdk/create-referral-link", "POST", {
|
|
65
|
-
referrerId,
|
|
66
|
-
rewardEventName
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
async trackReferral(referralCode, rewardEventName) {
|
|
70
|
-
return this.request("/api/v1/sdk/track-referral", "POST", {
|
|
71
|
-
referralCode,
|
|
72
|
-
rewardEventName
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async trackRewardEvent(refereeId, referralTrackingId, eventName) {
|
|
76
|
-
return this.request("/api/v1/sdk/track-reward-event", "POST", {
|
|
77
|
-
refereeId,
|
|
78
|
-
referralTrackingId,
|
|
79
|
-
eventName
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
// src/storage.ts
|
|
85
|
-
var StorageManager = class _StorageManager {
|
|
86
|
-
static REFERRAL_CODE_KEY = "gr_ref_code";
|
|
87
|
-
static TRACKED_REFERRAL_KEY = "gr_tracked_referral";
|
|
88
|
-
options = {};
|
|
89
|
-
constructor(options) {
|
|
90
|
-
if (options) {
|
|
91
|
-
this.options = options;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// Helper to set a cookie
|
|
95
|
-
setCookie(name, value, days = 30) {
|
|
96
|
-
if (typeof document === "undefined") return;
|
|
97
|
-
let expires = "";
|
|
98
|
-
if (days) {
|
|
99
|
-
const date = /* @__PURE__ */ new Date();
|
|
100
|
-
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
|
|
101
|
-
expires = `; expires=${date.toUTCString()}`;
|
|
102
|
-
}
|
|
103
|
-
let domain = "";
|
|
104
|
-
if (this.options.cookieDomain) {
|
|
105
|
-
domain = `; domain=${this.options.cookieDomain}`;
|
|
106
|
-
}
|
|
107
|
-
document.cookie = `${name}=${value || ""}${expires}${domain}; path=/; SameSite=Lax`;
|
|
108
|
-
}
|
|
109
|
-
// Helper to get a cookie
|
|
110
|
-
getCookie(name) {
|
|
111
|
-
if (typeof document === "undefined") return null;
|
|
112
|
-
const nameEQ = `${name}=`;
|
|
113
|
-
const ca = document.cookie.split(";");
|
|
114
|
-
for (let i = 0; i < ca.length; i++) {
|
|
115
|
-
let c = ca[i];
|
|
116
|
-
while (c.charAt(0) === " ") c = c.substring(1, c.length);
|
|
117
|
-
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
getReferralCode() {
|
|
122
|
-
return this.getCookie(_StorageManager.REFERRAL_CODE_KEY);
|
|
123
|
-
}
|
|
124
|
-
setReferralCode(code) {
|
|
125
|
-
this.setCookie(_StorageManager.REFERRAL_CODE_KEY, code, 30);
|
|
126
|
-
}
|
|
127
|
-
setTrackedReferral(trackingId) {
|
|
128
|
-
this.setCookie(_StorageManager.TRACKED_REFERRAL_KEY, trackingId, 30);
|
|
129
|
-
}
|
|
130
|
-
getTrackedReferral() {
|
|
131
|
-
return this.getCookie(_StorageManager.TRACKED_REFERRAL_KEY);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/referral-modal.ts
|
|
136
|
-
var ReferralModal = class {
|
|
137
|
-
referrerExperience;
|
|
138
|
-
deps;
|
|
139
|
-
host = null;
|
|
140
|
-
shadow = null;
|
|
141
|
-
overlay = null;
|
|
142
|
-
content = null;
|
|
143
|
-
constructor(deps, referrerExperience) {
|
|
144
|
-
this.deps = deps;
|
|
145
|
-
this.referrerExperience = referrerExperience;
|
|
146
|
-
}
|
|
147
|
-
show(options, container) {
|
|
148
|
-
if (this.host) return;
|
|
149
|
-
this.createDom(options, container);
|
|
150
|
-
this.bindEvents();
|
|
151
|
-
if (!container) {
|
|
152
|
-
document.body.style.overflow = "hidden";
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
hide() {
|
|
156
|
-
if (!this.host) return;
|
|
157
|
-
if (this.host && this.host.parentNode) {
|
|
158
|
-
this.host.parentNode.removeChild(this.host);
|
|
159
|
-
}
|
|
160
|
-
this.host = null;
|
|
161
|
-
this.overlay = null;
|
|
162
|
-
this.content = null;
|
|
163
|
-
this.shadow = null;
|
|
164
|
-
document.body.style.overflow = "";
|
|
165
|
-
}
|
|
166
|
-
createDom(options, container) {
|
|
167
|
-
const resolvedOptions = {
|
|
168
|
-
...this.referrerExperience,
|
|
169
|
-
...options ?? {}
|
|
170
|
-
};
|
|
171
|
-
const baseTheme = this.getTheme();
|
|
172
|
-
const theme = {
|
|
173
|
-
...baseTheme,
|
|
174
|
-
colorPrimary: resolvedOptions.modal?.theme?.primaryColor || baseTheme.colorPrimary,
|
|
175
|
-
colorBackground: resolvedOptions.modal?.theme?.backgroundColor || baseTheme.colorBackground,
|
|
176
|
-
colorTint: resolvedOptions.modal?.theme?.tintColor || baseTheme.colorTint
|
|
177
|
-
};
|
|
178
|
-
const isEmbedded = !!container;
|
|
179
|
-
this.host = document.createElement("div");
|
|
180
|
-
this.host.style.all = "initial";
|
|
181
|
-
if (!isEmbedded) {
|
|
182
|
-
this.host.style.position = "absolute";
|
|
183
|
-
this.host.style.zIndex = "2147483647";
|
|
184
|
-
} else {
|
|
185
|
-
this.host.style.display = "block";
|
|
186
|
-
this.host.style.width = "100%";
|
|
187
|
-
this.host.style.height = "100%";
|
|
188
|
-
}
|
|
189
|
-
this.host.id = "growth-rail-modal-host";
|
|
190
|
-
this.host.style.setProperty("--gr-primary", theme.colorPrimary);
|
|
191
|
-
this.host.style.setProperty("--gr-text", theme.colorText);
|
|
192
|
-
this.host.style.setProperty("--gr-text-secondary", theme.colorTextSecondary);
|
|
193
|
-
this.host.style.setProperty("--gr-bg", theme.colorBackground);
|
|
194
|
-
this.host.style.setProperty("--gr-tint", theme.colorTint);
|
|
195
|
-
this.host.style.setProperty("--gr-surface", theme.colorSurface);
|
|
196
|
-
this.host.style.setProperty("--gr-border", theme.colorBorder);
|
|
197
|
-
this.host.style.setProperty("--gr-error", theme.colorError);
|
|
198
|
-
this.host.style.setProperty("--gr-radius", theme.borderRadius);
|
|
199
|
-
this.host.style.setProperty("--gr-font", 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif');
|
|
200
|
-
this.shadow = this.host.attachShadow({ mode: "open" });
|
|
201
|
-
const style = document.createElement("style");
|
|
202
|
-
style.textContent = `
|
|
203
|
-
:host { all: initial; display: block; }
|
|
204
|
-
* { box-sizing: border-box; }
|
|
205
|
-
|
|
206
|
-
@keyframes gr-fade-in { from { opacity: 0; } to { opacity: 1; } }
|
|
207
|
-
@keyframes gr-slide-up { from { opacity: 0; transform: translateY(20px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
|
|
208
|
-
@keyframes gr-slide-in-right { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
|
|
209
|
-
@keyframes gr-slide-in-left { from { opacity: 0; transform: translateX(-100%); } to { opacity: 1; transform: translateX(0); } }
|
|
210
|
-
|
|
211
|
-
.gr-overlay {
|
|
212
|
-
position: fixed;
|
|
213
|
-
top: 0; left: 0; width: 100vw; height: 100vh;
|
|
214
|
-
display: flex;
|
|
215
|
-
z-index: 2147483647;
|
|
216
|
-
font-family: var(--gr-font);
|
|
217
|
-
animation: gr-fade-in 0.2s ease-out forwards;
|
|
218
|
-
backdrop-filter: blur(4px);
|
|
219
|
-
}
|
|
220
|
-
.gr-overlay--modal {
|
|
221
|
-
background-color: var(--gr-tint);
|
|
222
|
-
align-items: center;
|
|
223
|
-
justify-content: center;
|
|
224
|
-
}
|
|
225
|
-
.gr-overlay--drawer {
|
|
226
|
-
background-color: var(--gr-tint);
|
|
227
|
-
align-items: flex-start;
|
|
228
|
-
justify-content: flex-start;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
.gr-container {
|
|
232
|
-
position: relative;
|
|
233
|
-
background-color: var(--gr-bg);
|
|
234
|
-
color: var(--gr-text);
|
|
235
|
-
padding: 32px;
|
|
236
|
-
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/* Embedded Variant */
|
|
240
|
-
.gr-container--embedded {
|
|
241
|
-
width: 100%;
|
|
242
|
-
height: 100%;
|
|
243
|
-
box-shadow: none;
|
|
244
|
-
border: 1px solid var(--gr-border);
|
|
245
|
-
border-radius: var(--gr-radius);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/* Modal Variant */
|
|
249
|
-
.gr-container--modal {
|
|
250
|
-
width: 90%;
|
|
251
|
-
max-width: 480px;
|
|
252
|
-
border-radius: var(--gr-radius);
|
|
253
|
-
animation: gr-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/* Drawer Variant */
|
|
257
|
-
.gr-container--drawer {
|
|
258
|
-
position: absolute;
|
|
259
|
-
width: 400px;
|
|
260
|
-
max-width: calc(100vw - 20px);
|
|
261
|
-
max-height: calc(100vh - 40px);
|
|
262
|
-
overflow-y: auto;
|
|
263
|
-
}
|
|
264
|
-
.gr-container--right {
|
|
265
|
-
right: 0;
|
|
266
|
-
border-top-left-radius: var(--gr-radius);
|
|
267
|
-
border-bottom-left-radius: var(--gr-radius);
|
|
268
|
-
animation: gr-slide-in-right 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
269
|
-
}
|
|
270
|
-
.gr-container--left {
|
|
271
|
-
left: 0;
|
|
272
|
-
border-top-right-radius: var(--gr-radius);
|
|
273
|
-
border-bottom-right-radius: var(--gr-radius);
|
|
274
|
-
animation: gr-slide-in-left 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
275
|
-
}
|
|
276
|
-
.gr-container--top { top: 100px; }
|
|
277
|
-
.gr-container--bottom { bottom: 100px; }
|
|
278
|
-
|
|
279
|
-
.gr-close-btn {
|
|
280
|
-
position: absolute; top: 20px; right: 20px;
|
|
281
|
-
background: transparent; border: none; cursor: pointer;
|
|
282
|
-
color: #9ca3af; padding: 4px; border-radius: 50%;
|
|
283
|
-
display: flex; alignItems: center; justifyContent: center;
|
|
284
|
-
transition: all 0.2s;
|
|
285
|
-
}
|
|
286
|
-
.gr-close-btn:hover { background-color: var(--gr-surface); color: var(--gr-text); }
|
|
287
|
-
|
|
288
|
-
.gr-header { text-align: center; margin-bottom: 28px; }
|
|
289
|
-
.gr-icon-lg { font-size: 32px; margin-bottom: 12px; }
|
|
290
|
-
|
|
291
|
-
.gr-title {
|
|
292
|
-
margin: 0 0 8px 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em;
|
|
293
|
-
}
|
|
294
|
-
.gr-subtitle {
|
|
295
|
-
margin: 0; font-size: 14px; line-height: 1.5; color: var(--gr-text-secondary);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
.gr-loading {
|
|
299
|
-
padding: 16px; background-color: var(--gr-surface); border-radius: 8px;
|
|
300
|
-
text-align: center; color: var(--gr-text-secondary); font-size: 14px;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
.gr-label {
|
|
304
|
-
display: block; font-size: 12px; font-weight: 600;
|
|
305
|
-
color: var(--gr-text-secondary); margin-bottom: 8px;
|
|
306
|
-
text-transform: uppercase; letter-spacing: 0.05em;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
.gr-share-label {
|
|
310
|
-
text-align: center; margin-bottom: 16px; font-size: 13px; font-weight: 500;
|
|
311
|
-
color: var(--gr-text-secondary); display: flex; align-items: center; gap: 12px;
|
|
312
|
-
}
|
|
313
|
-
.gr-divider { flex: 1; height: 1px; background: var(--gr-border); }
|
|
314
|
-
|
|
315
|
-
.gr-social-container {
|
|
316
|
-
display: flex; gap: 16px; justify-content: center; flex-wrap: wrap;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
.gr-btn {
|
|
320
|
-
padding: 14px;
|
|
321
|
-
font-size: 15px;
|
|
322
|
-
font-weight: 600;
|
|
323
|
-
background-color: var(--gr-primary);
|
|
324
|
-
color: #ffffff;
|
|
325
|
-
border: none;
|
|
326
|
-
border-radius: var(--gr-radius);
|
|
327
|
-
cursor: pointer;
|
|
328
|
-
transition: all 0.2s ease;
|
|
329
|
-
text-align: center;
|
|
330
|
-
width: 100%;
|
|
331
|
-
display: block;
|
|
332
|
-
}
|
|
333
|
-
.gr-btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
|
|
334
|
-
.gr-btn:active { transform: translateY(0); filter: brightness(0.95); }
|
|
335
|
-
.gr-btn:disabled { opacity: 0.7; cursor: not-allowed; }
|
|
336
|
-
|
|
337
|
-
.gr-btn--sm {
|
|
338
|
-
padding: 8px 16px;
|
|
339
|
-
font-size: 13px;
|
|
340
|
-
width: auto;
|
|
341
|
-
border-radius: calc(var(--gr-radius) - 4px);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
.gr-input-group {
|
|
345
|
-
display: flex;
|
|
346
|
-
align-items: center;
|
|
347
|
-
background-color: var(--gr-surface);
|
|
348
|
-
border: 1px solid var(--gr-border);
|
|
349
|
-
border-radius: var(--gr-radius);
|
|
350
|
-
padding: 4px;
|
|
351
|
-
margin-bottom: 24px;
|
|
352
|
-
}
|
|
353
|
-
.gr-input-group:focus-within {
|
|
354
|
-
border-color: var(--gr-primary);
|
|
355
|
-
box-shadow: 0 0 0 3px var(--gr-surface);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
.gr-input {
|
|
359
|
-
flex: 1;
|
|
360
|
-
padding: 10px 12px;
|
|
361
|
-
font-size: 14px;
|
|
362
|
-
border: none;
|
|
363
|
-
background: transparent;
|
|
364
|
-
color: var(--gr-text);
|
|
365
|
-
outline: none;
|
|
366
|
-
font-family: monospace;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
.gr-social-btn {
|
|
370
|
-
display: flex; align-items: center; justify-content: center;
|
|
371
|
-
width: 42px; height: 42px;
|
|
372
|
-
border-radius: 50%;
|
|
373
|
-
background-color: var(--gr-surface);
|
|
374
|
-
color: var(--gr-text-secondary);
|
|
375
|
-
border: 1px solid var(--gr-border);
|
|
376
|
-
transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
377
|
-
cursor: pointer;
|
|
378
|
-
}
|
|
379
|
-
.gr-social-btn:hover { transform: scale(1.15) rotate(3deg); color: #fff; }
|
|
380
|
-
|
|
381
|
-
.gr-powered-by {
|
|
382
|
-
margin-top: 24px;
|
|
383
|
-
text-align: center;
|
|
384
|
-
font-size: 11px;
|
|
385
|
-
color: #9ca3af;
|
|
386
|
-
display: flex;
|
|
387
|
-
align-items: center;
|
|
388
|
-
justify-content: center;
|
|
389
|
-
gap: 4px;
|
|
390
|
-
opacity: 0.8;
|
|
391
|
-
}
|
|
392
|
-
.gr-powered-by a {
|
|
393
|
-
color: inherit;
|
|
394
|
-
text-decoration: none;
|
|
395
|
-
font-weight: 600;
|
|
396
|
-
transition: opacity 0.2s;
|
|
397
|
-
}
|
|
398
|
-
.gr-powered-by a:hover { opacity: 1; text-decoration: underline; }
|
|
399
|
-
`;
|
|
400
|
-
this.shadow.appendChild(style);
|
|
401
|
-
this.content = document.createElement("div");
|
|
402
|
-
const isDrawer = resolvedOptions.modal.type === "drawer";
|
|
403
|
-
const position = resolvedOptions.trigger.position || "top-right";
|
|
404
|
-
const contentClasses = ["gr-container"];
|
|
405
|
-
if (isEmbedded) {
|
|
406
|
-
contentClasses.push("gr-container--embedded");
|
|
407
|
-
this.content.className = contentClasses.join(" ");
|
|
408
|
-
this.renderInternalContent(theme, options, isEmbedded);
|
|
409
|
-
this.shadow.appendChild(this.content);
|
|
410
|
-
if (container) {
|
|
411
|
-
container.appendChild(this.host);
|
|
412
|
-
}
|
|
413
|
-
} else {
|
|
414
|
-
this.overlay = document.createElement("div");
|
|
415
|
-
this.overlay.className = `gr-overlay ${isDrawer ? "gr-overlay--drawer" : "gr-overlay--modal"}`;
|
|
416
|
-
if (isDrawer) {
|
|
417
|
-
contentClasses.push("gr-container--drawer");
|
|
418
|
-
if (position.includes("right")) contentClasses.push("gr-container--right");
|
|
419
|
-
else contentClasses.push("gr-container--left");
|
|
420
|
-
if (position.includes("bottom")) contentClasses.push("gr-container--bottom");
|
|
421
|
-
else contentClasses.push("gr-container--top");
|
|
422
|
-
} else {
|
|
423
|
-
contentClasses.push("gr-container--modal");
|
|
424
|
-
}
|
|
425
|
-
this.content.className = contentClasses.join(" ");
|
|
426
|
-
this.renderInternalContent(theme, options, isEmbedded);
|
|
427
|
-
this.overlay.appendChild(this.content);
|
|
428
|
-
this.shadow.appendChild(this.overlay);
|
|
429
|
-
document.body.appendChild(this.host);
|
|
430
|
-
this.overlay.onclick = (e) => {
|
|
431
|
-
if (e.target === this.overlay) this.hide();
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
getTheme() {
|
|
436
|
-
return {
|
|
437
|
-
colorPrimary: "#2563eb",
|
|
438
|
-
colorText: "#111827",
|
|
439
|
-
colorTextSecondary: "#6b7280",
|
|
440
|
-
colorBackground: "#ffffff",
|
|
441
|
-
colorTint: "#f9fafb",
|
|
442
|
-
colorSurface: "#f9fafb",
|
|
443
|
-
colorBorder: "#e5e7eb",
|
|
444
|
-
colorError: "#ef4444",
|
|
445
|
-
borderRadius: "16px"
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
async renderInternalContent(theme, options, isEmbedded = false) {
|
|
449
|
-
if (!this.content) return;
|
|
450
|
-
this.content.innerHTML = "";
|
|
451
|
-
if (!isEmbedded) {
|
|
452
|
-
const closeBtn = document.createElement("button");
|
|
453
|
-
closeBtn.className = "gr-close-btn";
|
|
454
|
-
closeBtn.innerHTML = `
|
|
1
|
+
"use strict";var y=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var E=(d,e,r)=>e in d?y(d,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):d[e]=r;var C=(d,e)=>{for(var r in e)y(d,r,{get:e[r],enumerable:!0})},T=(d,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of R(e))!k.call(d,n)&&n!==r&&y(d,n,{get:()=>e[n],enumerable:!(i=w(e,n))||i.enumerable});return d};var P=d=>T(y({},"__esModule",{value:!0}),d);var a=(d,e,r)=>E(d,typeof e!="symbol"?e+"":e,r);var U={};C(U,{GrowthRail:()=>m,ReferralModal:()=>u});module.exports=P(U);var b=class{constructor(e){a(this,"baseUrl");a(this,"apiKey");let r=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=r||"http://hw84ko0ok4ccws4sws8gos0o.193.31.30.10.sslip.io",this.apiKey=e.apiKey}async request(e,r,i){let n={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.apiKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:r,headers:n,body:i?JSON.stringify(i):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async createReferralLink(e,r){return this.request("/api/v1/sdk/create-referral-link","POST",{referrerId:e,rewardEventName:r})}async trackReferral(e,r){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:r})}async trackRewardEvent(e,r,i){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:r,eventName:i})}};var f=class f{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,r,i=30){if(typeof document>"u")return;let n="";if(i){let s=new Date;s.setTime(s.getTime()+i*24*60*60*1e3),n=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${r||""}${n}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let r=`${e}=`,i=document.cookie.split(";");for(let n=0;n<i.length;n++){let o=i[n];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(r)===0)return o.substring(r.length,o.length)}return null}getReferralCode(){return this.getCookie(f.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(f.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(f.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(f.TRACKED_REFERRAL_KEY)}};a(f,"REFERRAL_CODE_KEY","gr_ref_code"),a(f,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var x=f;var u=class{constructor(e,r){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=r}show(e,r){this.host||(this.createDom(e,r),this.bindEvents(),r||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,r){let i={...this.referrerExperience,...e??{}},n=this.getTheme(),o={...n,colorPrimary:i.modal?.theme?.primaryColor||n.colorPrimary,colorBackground:i.modal?.theme?.backgroundColor||n.colorBackground,colorTint:i.modal?.theme?.tintColor||n.colorTint},s=!!r;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let c=document.createElement("style");c.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px)}.gr-overlay--modal{background-color:var(--gr-tint);align-items:center;justify-content:center}.gr-overlay--drawer{background-color:var(--gr-tint);align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 20px 25px -5px rgba(0,0,0,.1),0 10px 10px -5px rgba(0,0,0,.04)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(c),this.content=document.createElement("div");let p=i.modal.type==="drawer",l=i.trigger.position||"top-right",h=["gr-container"];s?(h.push("gr-container--embedded"),this.content.className=h.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),r&&r.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${p?"gr-overlay--drawer":"gr-overlay--modal"}`,p?(h.push("gr-container--drawer"),l.includes("right")?h.push("gr-container--right"):h.push("gr-container--left"),l.includes("bottom")?h.push("gr-container--bottom"):h.push("gr-container--top")):h.push("gr-container--modal"),this.content.className=h.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=g=>{g.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,r,i=!1){if(!this.content)return;if(this.content.innerHTML="",!i){let g=document.createElement("button");g.className="gr-close-btn",g.innerHTML=`
|
|
455
2
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
456
3
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
457
4
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
458
5
|
</svg>
|
|
459
|
-
|
|
460
|
-
closeBtn.onclick = () => this.hide();
|
|
461
|
-
this.content.appendChild(closeBtn);
|
|
462
|
-
}
|
|
463
|
-
const header = document.createElement("div");
|
|
464
|
-
header.className = "gr-header";
|
|
465
|
-
const icon = document.createElement("div");
|
|
466
|
-
icon.className = "gr-icon-lg";
|
|
467
|
-
icon.innerHTML = "\u{1F381}";
|
|
468
|
-
header.appendChild(icon);
|
|
469
|
-
const title = document.createElement("h3");
|
|
470
|
-
title.className = "gr-title";
|
|
471
|
-
title.textContent = options?.title ?? this.referrerExperience.modal.title ?? "Invite Friends & Earn";
|
|
472
|
-
header.appendChild(title);
|
|
473
|
-
const subtitle = document.createElement("p");
|
|
474
|
-
subtitle.className = "gr-subtitle";
|
|
475
|
-
subtitle.textContent = "Share your unique link and earn rewards for every friend who signs up.";
|
|
476
|
-
header.appendChild(subtitle);
|
|
477
|
-
this.content.appendChild(header);
|
|
478
|
-
if (!this.deps.isUserReady()) {
|
|
479
|
-
const msg = document.createElement("div");
|
|
480
|
-
msg.className = "gr-loading";
|
|
481
|
-
msg.textContent = "Please log in to view your referral dashboard.";
|
|
482
|
-
this.content.appendChild(msg);
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
let referralLink = this.deps.getReferralLink();
|
|
486
|
-
const actionContainer = document.createElement("div");
|
|
487
|
-
this.renderLinkView(actionContainer, referralLink, theme);
|
|
488
|
-
this.content.appendChild(actionContainer);
|
|
489
|
-
if (referralLink) {
|
|
490
|
-
this.renderSocialShare(this.content, referralLink, theme);
|
|
491
|
-
}
|
|
492
|
-
const poweredBy = document.createElement("div");
|
|
493
|
-
poweredBy.className = "gr-powered-by";
|
|
494
|
-
poweredBy.innerHTML = `
|
|
6
|
+
`,g.onclick=()=>this.hide(),this.content.appendChild(g)}let n=document.createElement("div");n.className="gr-header";let o=document.createElement("div");o.className="gr-icon-lg",o.innerHTML="\u{1F381}",n.appendChild(o);let s=document.createElement("h3");s.className="gr-title",s.textContent=r?.title??this.referrerExperience.modal.title??"Invite Friends & Earn",n.appendChild(s);let c=document.createElement("p");if(c.className="gr-subtitle",c.textContent="Share your unique link and earn rewards for every friend who signs up.",n.appendChild(c),this.content.appendChild(n),!this.deps.isUserReady()){let g=document.createElement("div");g.className="gr-loading",g.textContent="Please log in to view your referral dashboard.",this.content.appendChild(g);return}let p=this.deps.getReferralLink(),l=document.createElement("div");this.renderLinkView(l,p,e),this.content.appendChild(l),p&&this.renderSocialShare(this.content,p,e);let h=document.createElement("div");h.className="gr-powered-by",h.innerHTML=`
|
|
495
7
|
Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
|
|
496
|
-
|
|
497
|
-
this.content.appendChild(poweredBy);
|
|
498
|
-
}
|
|
499
|
-
renderLinkView(container, link, theme) {
|
|
500
|
-
const label = document.createElement("label");
|
|
501
|
-
label.className = "gr-label";
|
|
502
|
-
label.textContent = "Your unique link";
|
|
503
|
-
container.appendChild(label);
|
|
504
|
-
const linkGroup = document.createElement("div");
|
|
505
|
-
linkGroup.className = "gr-input-group";
|
|
506
|
-
const input = document.createElement("input");
|
|
507
|
-
input.className = "gr-input";
|
|
508
|
-
input.type = "text";
|
|
509
|
-
input.value = link;
|
|
510
|
-
input.readOnly = true;
|
|
511
|
-
const copyBtn = document.createElement("button");
|
|
512
|
-
copyBtn.className = "gr-btn gr-btn--sm";
|
|
513
|
-
copyBtn.textContent = "Copy";
|
|
514
|
-
copyBtn.onclick = async () => {
|
|
515
|
-
try {
|
|
516
|
-
await navigator.clipboard.writeText(link);
|
|
517
|
-
const originalText = copyBtn.textContent;
|
|
518
|
-
copyBtn.textContent = "Copied!";
|
|
519
|
-
copyBtn.style.backgroundColor = "#10b981";
|
|
520
|
-
setTimeout(() => {
|
|
521
|
-
copyBtn.textContent = originalText;
|
|
522
|
-
copyBtn.style.backgroundColor = "";
|
|
523
|
-
}, 2e3);
|
|
524
|
-
} catch (err) {
|
|
525
|
-
console.error("Failed to copy", err);
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
linkGroup.appendChild(input);
|
|
529
|
-
linkGroup.appendChild(copyBtn);
|
|
530
|
-
container.appendChild(linkGroup);
|
|
531
|
-
}
|
|
532
|
-
renderSocialShare(container, link, theme) {
|
|
533
|
-
const shareContainer = document.createElement("div");
|
|
534
|
-
const label = document.createElement("div");
|
|
535
|
-
label.className = "gr-share-label";
|
|
536
|
-
label.innerHTML = `<span class="gr-divider"></span>Share via<span class="gr-divider"></span>`;
|
|
537
|
-
shareContainer.appendChild(label);
|
|
538
|
-
const buttonsContainer = document.createElement("div");
|
|
539
|
-
buttonsContainer.className = "gr-social-container";
|
|
540
|
-
const platforms = [
|
|
541
|
-
{ 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!` },
|
|
542
|
-
{ 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)}` },
|
|
543
|
-
{ 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)}` },
|
|
544
|
-
{ 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)}` },
|
|
545
|
-
{ 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)}` }
|
|
546
|
-
];
|
|
547
|
-
platforms.forEach((p) => {
|
|
548
|
-
const btn = document.createElement("a");
|
|
549
|
-
btn.href = p.url;
|
|
550
|
-
btn.target = "_blank";
|
|
551
|
-
btn.rel = "noopener noreferrer";
|
|
552
|
-
btn.className = "gr-social-btn";
|
|
553
|
-
btn.innerHTML = p.icon;
|
|
554
|
-
btn.title = `Share on ${p.name}`;
|
|
555
|
-
btn.onmouseenter = () => {
|
|
556
|
-
btn.style.backgroundColor = p.color;
|
|
557
|
-
btn.style.color = "#ffffff";
|
|
558
|
-
btn.style.borderColor = p.color;
|
|
559
|
-
};
|
|
560
|
-
btn.onmouseleave = () => {
|
|
561
|
-
btn.style.backgroundColor = "";
|
|
562
|
-
btn.style.color = "";
|
|
563
|
-
btn.style.borderColor = "";
|
|
564
|
-
};
|
|
565
|
-
buttonsContainer.appendChild(btn);
|
|
566
|
-
});
|
|
567
|
-
shareContainer.appendChild(buttonsContainer);
|
|
568
|
-
container.appendChild(shareContainer);
|
|
569
|
-
}
|
|
570
|
-
bindEvents() {
|
|
571
|
-
if (this.overlay) {
|
|
572
|
-
this.overlay.onclick = (e) => {
|
|
573
|
-
if (e.target === this.overlay) {
|
|
574
|
-
this.hide();
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
|
|
581
|
-
// src/trigger-button.ts
|
|
582
|
-
var TriggerButton = class {
|
|
583
|
-
options;
|
|
584
|
-
host = null;
|
|
585
|
-
shadow = null;
|
|
586
|
-
element = null;
|
|
587
|
-
constructor(options) {
|
|
588
|
-
this.options = options;
|
|
589
|
-
}
|
|
590
|
-
mount() {
|
|
591
|
-
if (this.host) return;
|
|
592
|
-
this.createDom();
|
|
593
|
-
}
|
|
594
|
-
unmount() {
|
|
595
|
-
if (this.host && this.host.parentNode) {
|
|
596
|
-
document.body.removeChild(this.host);
|
|
597
|
-
}
|
|
598
|
-
this.host = null;
|
|
599
|
-
this.shadow = null;
|
|
600
|
-
this.element = null;
|
|
601
|
-
}
|
|
602
|
-
createDom() {
|
|
603
|
-
this.host = document.createElement("div");
|
|
604
|
-
this.host.style.all = "initial";
|
|
605
|
-
this.host.style.position = "absolute";
|
|
606
|
-
this.host.style.zIndex = "2147483646";
|
|
607
|
-
const offset = { x: 0, y: 100 };
|
|
608
|
-
this.host.style.setProperty("--gr-offset-y", `${offset.y}px`);
|
|
609
|
-
this.shadow = this.host.attachShadow({ mode: "open" });
|
|
610
|
-
const style = document.createElement("style");
|
|
611
|
-
style.textContent = `
|
|
612
|
-
:host {
|
|
613
|
-
all: initial;
|
|
614
|
-
display: block;
|
|
615
|
-
}
|
|
616
|
-
@keyframes gr-shimmer {
|
|
617
|
-
0% { transform: translateX(-150%) skewX(-15deg); }
|
|
618
|
-
50% { transform: translateX(150%) skewX(-15deg); }
|
|
619
|
-
100% { transform: translateX(150%) skewX(-15deg); }
|
|
620
|
-
}
|
|
621
|
-
.gr-floating-btn {
|
|
622
|
-
position: fixed;
|
|
623
|
-
width: 50px;
|
|
624
|
-
height: 50px;
|
|
625
|
-
background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
|
|
626
|
-
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
|
627
|
-
cursor: pointer;
|
|
628
|
-
z-index: 2147483646;
|
|
629
|
-
display: flex;
|
|
630
|
-
align-items: center;
|
|
631
|
-
justify-content: center;
|
|
632
|
-
transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, width 0.2s;
|
|
633
|
-
overflow: hidden;
|
|
634
|
-
font-family: system-ui, -apple-system, sans-serif;
|
|
635
|
-
box-sizing: border-box;
|
|
636
|
-
}
|
|
637
|
-
.gr-floating-btn * {
|
|
638
|
-
box-sizing: border-box;
|
|
639
|
-
}
|
|
640
|
-
.gr-floating-btn:hover {
|
|
641
|
-
transform: scale(1.05);
|
|
642
|
-
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
|
643
|
-
}
|
|
644
|
-
.gr-floating-btn--right {
|
|
645
|
-
right: 0;
|
|
646
|
-
border-top-left-radius: 8px;
|
|
647
|
-
border-bottom-left-radius: 8px;
|
|
648
|
-
border-top-right-radius: 0;
|
|
649
|
-
border-bottom-right-radius: 0;
|
|
650
|
-
padding-left: 4px; /* Optical balance */
|
|
651
|
-
}
|
|
652
|
-
.gr-floating-btn--left {
|
|
653
|
-
left: 0;
|
|
654
|
-
border-top-right-radius: 8px;
|
|
655
|
-
border-bottom-right-radius: 8px;
|
|
656
|
-
border-top-left-radius: 0;
|
|
657
|
-
border-bottom-left-radius: 0;
|
|
658
|
-
padding-right: 4px;
|
|
659
|
-
}
|
|
660
|
-
.gr-floating-btn--bottom {
|
|
661
|
-
bottom: var(--gr-offset-y);
|
|
662
|
-
}
|
|
663
|
-
.gr-floating-btn--top {
|
|
664
|
-
top: var(--gr-offset-y);
|
|
665
|
-
}
|
|
666
|
-
.gr-floating-btn::after {
|
|
667
|
-
content: '';
|
|
668
|
-
position: absolute;
|
|
669
|
-
top: 0;
|
|
670
|
-
left: 0;
|
|
671
|
-
width: 100%;
|
|
672
|
-
height: 100%;
|
|
673
|
-
background: linear-gradient(to right, transparent 0%, rgba(255, 255, 255, 0.4) 50%, transparent 100%);
|
|
674
|
-
transform: translateX(-150%) skewX(-15deg);
|
|
675
|
-
animation: gr-shimmer 3s infinite;
|
|
676
|
-
}
|
|
677
|
-
.gr-icon {
|
|
678
|
-
color: white;
|
|
679
|
-
width: 24px;
|
|
680
|
-
height: 24px;
|
|
681
|
-
position: relative;
|
|
682
|
-
z-index: 10;
|
|
683
|
-
}
|
|
684
|
-
`;
|
|
685
|
-
this.shadow.appendChild(style);
|
|
686
|
-
this.element = document.createElement("div");
|
|
687
|
-
const position = this.options.position || "bottom-right";
|
|
688
|
-
const classes = ["gr-floating-btn"];
|
|
689
|
-
if (position.includes("right")) classes.push("gr-floating-btn--right");
|
|
690
|
-
else classes.push("gr-floating-btn--left");
|
|
691
|
-
if (position.includes("bottom")) classes.push("gr-floating-btn--bottom");
|
|
692
|
-
else classes.push("gr-floating-btn--top");
|
|
693
|
-
this.element.className = classes.join(" ");
|
|
694
|
-
this.element.innerHTML = `
|
|
8
|
+
`,this.content.appendChild(h)}renderLinkView(e,r,i){let n=document.createElement("label");n.className="gr-label",n.textContent="Your unique link",e.appendChild(n);let o=document.createElement("div");o.className="gr-input-group";let s=document.createElement("input");s.className="gr-input",s.type="text",s.value=r,s.readOnly=!0;let c=document.createElement("button");c.className="gr-btn gr-btn--sm",c.textContent="Copy",c.onclick=async()=>{try{await navigator.clipboard.writeText(r);let p=c.textContent;c.textContent="Copied!",c.style.backgroundColor="#10b981",setTimeout(()=>{c.textContent=p,c.style.backgroundColor=""},2e3)}catch(p){console.error("Failed to copy",p)}},o.appendChild(s),o.appendChild(c),e.appendChild(o)}renderSocialShare(e,r,i){let n=document.createElement("div"),o=document.createElement("div");o.className="gr-share-label",o.innerHTML='<span class="gr-divider"></span>Share via<span class="gr-divider"></span>',n.appendChild(o);let s=document.createElement("div");s.className="gr-social-container",[{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(r)}&text=Check+this+out!`},{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(r)}`},{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(r)}`},{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(r)}`},{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(r)}`}].forEach(p=>{let l=document.createElement("a");l.href=p.url,l.target="_blank",l.rel="noopener noreferrer",l.className="gr-social-btn",l.innerHTML=p.icon,l.title=`Share on ${p.name}`,l.onmouseenter=()=>{l.style.backgroundColor=p.color,l.style.color="#ffffff",l.style.borderColor=p.color},l.onmouseleave=()=>{l.style.backgroundColor="",l.style.color="",l.style.borderColor=""},s.appendChild(l)}),n.appendChild(s),e.appendChild(n)}bindEvents(){this.overlay&&(this.overlay.onclick=e=>{e.target===this.overlay&&this.hide()})}};var v=class{constructor(e){a(this,"options");a(this,"host",null);a(this,"shadow",null);a(this,"element",null);this.options=e}mount(){this.host||this.createDom()}unmount(){this.host&&this.host.parentNode&&document.body.removeChild(this.host),this.host=null,this.shadow=null,this.element=null}createDom(){this.host=document.createElement("div"),this.host.style.all="initial",this.host.style.position="absolute",this.host.style.zIndex="2147483646";let e={x:0,y:100};this.host.style.setProperty("--gr-offset-y",`${e.y}px`),this.shadow=this.host.attachShadow({mode:"open"});let r=document.createElement("style");r.textContent=":host{all:initial;display:block}@keyframes gr-shimmer{0%{transform:translateX(-150%) skewX(-15deg)}50%{transform:translateX(150%) skewX(-15deg)}100% {transform:translateX(150%) skewX(-15deg)}}.gr-floating-btn{position:fixed;width:50px;height:50px;background:linear-gradient(135deg,#6366f1 0%,#a855f7 100%);box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,0.06);cursor:pointer;z-index:2147483646;display:flex;align-items:center;justify-content:center;transition:transform .2s cubic-bezier(.34,1.56,.64,1),box-shadow .2s ease,width .2s;overflow:hidden;font-family:system-ui,-apple-system,sans-serif;box-sizing:border-box}.gr-floating-btn *{box-sizing:border-box}.gr-floating-btn:hover{transform:scale(1.05);box-shadow:0 10px 15px -3px rgba(0,0,0,.1),0 4px 6px -2px rgba(0,0,0,.05)}.gr-floating-btn--right{right:0;border-top-left-radius:8px;border-bottom-left-radius:8px;border-top-right-radius:0;border-bottom-right-radius:0;padding-left:4px}.gr-floating-btn--left{left:0;border-top-right-radius:8px;border-bottom-right-radius:8px;border-top-left-radius:0;border-bottom-left-radius:0;padding-right:4px}.gr-floating-btn--bottom{bottom:var(--gr-offset-y)}.gr-floating-btn--top{top:var(--gr-offset-y)}.gr-floating-btn::after{content:'';position:absolute;top:0;left:0;width:100%;height:100%;background:linear-gradient(to right,transparent 0%,rgba(255,255,255,0.4) 50%,transparent 100%);transform:translateX(-150%) skewX(-15deg);animation:gr-shimmer 3s infinite}.gr-icon{color:#fff;width:24px;height:24px;position:relative;z-index:10}",this.shadow.appendChild(r),this.element=document.createElement("div");let i=this.options.position||"bottom-right",n=["gr-floating-btn"];i.includes("right")?n.push("gr-floating-btn--right"):n.push("gr-floating-btn--left"),i.includes("bottom")?n.push("gr-floating-btn--bottom"):n.push("gr-floating-btn--top"),this.element.className=n.join(" "),this.element.innerHTML=`
|
|
695
9
|
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
696
10
|
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
697
11
|
<rect x="2" y="7" width="20" height="5"></rect>
|
|
@@ -699,178 +13,5 @@ var TriggerButton = class {
|
|
|
699
13
|
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
700
14
|
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
701
15
|
</svg>
|
|
702
|
-
|
|
703
|
-
this.element.onclick = () => {
|
|
704
|
-
GrowthRail.showReferralDashboard();
|
|
705
|
-
};
|
|
706
|
-
this.shadow.appendChild(this.element);
|
|
707
|
-
document.body.appendChild(this.host);
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
// src/core.ts
|
|
712
|
-
var GrowthRail = class _GrowthRail {
|
|
713
|
-
static api;
|
|
714
|
-
static storage;
|
|
715
|
-
static options;
|
|
716
|
-
static currentUser = null;
|
|
717
|
-
static initialized = false;
|
|
718
|
-
static referralModal = null;
|
|
719
|
-
static floatingButton = null;
|
|
720
|
-
static experience = null;
|
|
721
|
-
static userReadyPromise = null;
|
|
722
|
-
static userReadyResolver = null;
|
|
723
|
-
constructor() {
|
|
724
|
-
}
|
|
725
|
-
static init(options) {
|
|
726
|
-
if (_GrowthRail.initialized) return;
|
|
727
|
-
_GrowthRail.options = options;
|
|
728
|
-
_GrowthRail.api = new APIClient(options);
|
|
729
|
-
_GrowthRail.storage = new StorageManager({ cookieDomain: options.cookieDomain });
|
|
730
|
-
_GrowthRail.initialized = true;
|
|
731
|
-
_GrowthRail.autoTrackReferral();
|
|
732
|
-
}
|
|
733
|
-
static isInitialized() {
|
|
734
|
-
return _GrowthRail.initialized;
|
|
735
|
-
}
|
|
736
|
-
static ensureInitialized() {
|
|
737
|
-
if (!_GrowthRail.initialized) {
|
|
738
|
-
throw new Error("GrowthRail.init() must be called before using the SDK");
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
static async loadReferrerExperience(experience) {
|
|
742
|
-
try {
|
|
743
|
-
_GrowthRail.createReferralModal(experience);
|
|
744
|
-
if (experience.trigger.show) {
|
|
745
|
-
_GrowthRail.createTriggerButton(experience.trigger);
|
|
746
|
-
}
|
|
747
|
-
} catch (error) {
|
|
748
|
-
console.error("GrowthRail: Failed to load referrer experience", error);
|
|
749
|
-
throw error;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
static createReferralModal(referrerExperience) {
|
|
753
|
-
_GrowthRail.referralModal = new ReferralModal({
|
|
754
|
-
isUserReady: () => _GrowthRail.isUserReady(),
|
|
755
|
-
getReferralLink: () => _GrowthRail.currentUser?.referralLink || ""
|
|
756
|
-
}, referrerExperience);
|
|
757
|
-
}
|
|
758
|
-
static async autoTrackReferral() {
|
|
759
|
-
if (typeof window === "undefined") return;
|
|
760
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
761
|
-
const refCode = urlParams.get("referralCode");
|
|
762
|
-
const refEventName = urlParams.get("rewardEventName");
|
|
763
|
-
if (refCode) {
|
|
764
|
-
const newUserExperience = await _GrowthRail.api.getNewUserExperience();
|
|
765
|
-
const trackingResult = await _GrowthRail.trackReferral(refCode, refEventName ?? void 0);
|
|
766
|
-
_GrowthRail.storage.setTrackedReferral(trackingResult.referralTrackingId);
|
|
767
|
-
trackingResult.promotionalText && newUserExperience.banner.show && _GrowthRail.createPromotionalBanner(trackingResult.promotionalText, newUserExperience);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
static async initAppUser(clientProvidedId) {
|
|
771
|
-
_GrowthRail.ensureInitialized();
|
|
772
|
-
const appUser = await _GrowthRail.api.initAppUser(clientProvidedId);
|
|
773
|
-
_GrowthRail.currentUser = { ...appUser, id: clientProvidedId };
|
|
774
|
-
_GrowthRail.experience = appUser.referrerExperience;
|
|
775
|
-
_GrowthRail.loadReferrerExperience(appUser.referrerExperience);
|
|
776
|
-
if (_GrowthRail.userReadyResolver) {
|
|
777
|
-
_GrowthRail.userReadyResolver(_GrowthRail.currentUser);
|
|
778
|
-
} else {
|
|
779
|
-
_GrowthRail.userReadyPromise = Promise.resolve(_GrowthRail.currentUser);
|
|
780
|
-
}
|
|
781
|
-
return appUser;
|
|
782
|
-
}
|
|
783
|
-
static async trackReferral(referralCode, rewardEventName) {
|
|
784
|
-
_GrowthRail.ensureInitialized();
|
|
785
|
-
return _GrowthRail.api.trackReferral(referralCode, rewardEventName);
|
|
786
|
-
}
|
|
787
|
-
static async trackRewardEvent(eventName) {
|
|
788
|
-
_GrowthRail.ensureInitialized();
|
|
789
|
-
const refereeId = _GrowthRail.currentUser?.id;
|
|
790
|
-
if (!refereeId) {
|
|
791
|
-
throw new Error("GrowthRail: User must be initialized before tracking a reward event.");
|
|
792
|
-
}
|
|
793
|
-
const referralTrackingId = _GrowthRail.storage.getTrackedReferral();
|
|
794
|
-
if (!referralTrackingId) {
|
|
795
|
-
throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");
|
|
796
|
-
}
|
|
797
|
-
return _GrowthRail.api.trackRewardEvent(refereeId, referralTrackingId, eventName);
|
|
798
|
-
}
|
|
799
|
-
static getReferralLink() {
|
|
800
|
-
if (!_GrowthRail.currentUser?.referralLink) {
|
|
801
|
-
throw new Error("GrowthRail: Referral Link not loaded or user not initialized");
|
|
802
|
-
}
|
|
803
|
-
return _GrowthRail.currentUser.referralLink;
|
|
804
|
-
}
|
|
805
|
-
static getReferralCode() {
|
|
806
|
-
return _GrowthRail.currentUser?.referralCode;
|
|
807
|
-
}
|
|
808
|
-
static getUserId() {
|
|
809
|
-
return _GrowthRail.currentUser?.id;
|
|
810
|
-
}
|
|
811
|
-
static isUserReady() {
|
|
812
|
-
return _GrowthRail.currentUser !== null;
|
|
813
|
-
}
|
|
814
|
-
static ensureUserReady() {
|
|
815
|
-
if (_GrowthRail.currentUser) {
|
|
816
|
-
return Promise.resolve(_GrowthRail.currentUser);
|
|
817
|
-
}
|
|
818
|
-
if (!_GrowthRail.userReadyPromise) {
|
|
819
|
-
_GrowthRail.userReadyPromise = new Promise((resolve) => {
|
|
820
|
-
_GrowthRail.userReadyResolver = resolve;
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
return _GrowthRail.userReadyPromise;
|
|
824
|
-
}
|
|
825
|
-
static async showReferralDashboard(options) {
|
|
826
|
-
_GrowthRail.ensureInitialized();
|
|
827
|
-
if (!_GrowthRail.experience) {
|
|
828
|
-
throw new Error("GrowthRail: Experience not loaded");
|
|
829
|
-
}
|
|
830
|
-
if (_GrowthRail.referralModal) {
|
|
831
|
-
_GrowthRail.referralModal.hide();
|
|
832
|
-
}
|
|
833
|
-
_GrowthRail.referralModal?.show(options);
|
|
834
|
-
}
|
|
835
|
-
static createPromotionalBanner(promotionalText, newUserExperience) {
|
|
836
|
-
if (typeof document === "undefined") return;
|
|
837
|
-
const banner = document.createElement("div");
|
|
838
|
-
banner.style.position = "fixed";
|
|
839
|
-
banner.style.top = newUserExperience.banner.position.split("-")[1] === "top" ? "0" : "auto";
|
|
840
|
-
banner.style.bottom = newUserExperience.banner.position.split("-")[1] === "bottom" ? "0" : "auto";
|
|
841
|
-
banner.style.left = newUserExperience.banner.position.split("-")[0] === "left" ? "0" : "auto";
|
|
842
|
-
banner.style.right = newUserExperience.banner.position.split("-")[0] === "right" ? "0" : "auto";
|
|
843
|
-
banner.style.width = "100%";
|
|
844
|
-
banner.style.margin = "auto";
|
|
845
|
-
banner.style.backgroundColor = "#f0f0f0";
|
|
846
|
-
banner.style.padding = "10px";
|
|
847
|
-
banner.style.textAlign = "center";
|
|
848
|
-
banner.style.zIndex = "10000";
|
|
849
|
-
banner.textContent = promotionalText;
|
|
850
|
-
document.body.appendChild(banner);
|
|
851
|
-
}
|
|
852
|
-
static createTriggerButton(options) {
|
|
853
|
-
if (typeof window === "undefined") return;
|
|
854
|
-
if (!_GrowthRail.experience) {
|
|
855
|
-
throw new Error("GrowthRail: Experience not loaded");
|
|
856
|
-
}
|
|
857
|
-
if (_GrowthRail.floatingButton) {
|
|
858
|
-
_GrowthRail.floatingButton.unmount();
|
|
859
|
-
}
|
|
860
|
-
const finalOptions = { ..._GrowthRail.experience?.trigger, ...options };
|
|
861
|
-
_GrowthRail.floatingButton = new TriggerButton(finalOptions);
|
|
862
|
-
_GrowthRail.floatingButton.mount();
|
|
863
|
-
}
|
|
864
|
-
static destroyTriggerButton() {
|
|
865
|
-
if (_GrowthRail.floatingButton) {
|
|
866
|
-
_GrowthRail.floatingButton.unmount();
|
|
867
|
-
_GrowthRail.floatingButton = null;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
872
|
-
0 && (module.exports = {
|
|
873
|
-
GrowthRail,
|
|
874
|
-
ReferralModal
|
|
875
|
-
});
|
|
16
|
+
`,this.element.onclick=()=>{m.showReferralDashboard()},this.shadow.appendChild(this.element),document.body.appendChild(this.host)}};var t=class t{constructor(){}static init(e){t.initialized||(t.options=e,t.api=new b(e),t.storage=new x({cookieDomain:e.cookieDomain}),t.initialized=!0,t.autoTrackReferral())}static isInitialized(){return t.initialized}static ensureInitialized(){if(!t.initialized)throw new Error("GrowthRail.init() must be called before using the SDK")}static async loadReferrerExperience(e){try{t.createReferralModal(e),e.trigger.show&&t.createTriggerButton(e.trigger)}catch(r){throw console.error("GrowthRail: Failed to load referrer experience",r),r}}static createReferralModal(e){t.referralModal=new u({isUserReady:()=>t.isUserReady(),getReferralLink:()=>t.currentUser?.referralLink||""},e)}static async autoTrackReferral(){if(typeof window>"u")return;let e=new URLSearchParams(window.location.search),r=e.get("referralCode"),i=e.get("rewardEventName");if(r){let n=await t.api.getNewUserExperience(),o=await t.trackReferral(r,i??void 0);t.storage.setTrackedReferral(o.referralTrackingId),o.promotionalText&&n.banner.show&&t.createPromotionalBanner(o.promotionalText,n)}}static async initAppUser(e){t.ensureInitialized();let r=await t.api.initAppUser(e);return t.currentUser={...r,id:e},t.experience=r.referrerExperience,t.loadReferrerExperience(r.referrerExperience),t.userReadyResolver?t.userReadyResolver(t.currentUser):t.userReadyPromise=Promise.resolve(t.currentUser),r}static async trackReferral(e,r){return t.ensureInitialized(),t.api.trackReferral(e,r)}static async trackRewardEvent(e){t.ensureInitialized();let r=t.currentUser?.id;if(!r)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let i=t.storage.getTrackedReferral();if(!i)throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");return t.api.trackRewardEvent(r,i,e)}static getReferralLink(){if(!t.currentUser?.referralLink)throw new Error("GrowthRail: Referral Link not loaded or user not initialized");return t.currentUser.referralLink}static getReferralCode(){return t.currentUser?.referralCode}static getUserId(){return t.currentUser?.id}static isUserReady(){return t.currentUser!==null}static ensureUserReady(){return t.currentUser?Promise.resolve(t.currentUser):(t.userReadyPromise||(t.userReadyPromise=new Promise(e=>{t.userReadyResolver=e})),t.userReadyPromise)}static async showReferralDashboard(e){if(t.ensureInitialized(),!t.experience)throw new Error("GrowthRail: Experience not loaded");t.referralModal&&t.referralModal.hide(),t.referralModal?.show(e)}static createPromotionalBanner(e,r){if(typeof document>"u")return;let i=document.createElement("div");i.style.position="fixed",i.style.top=r.banner.position.split("-")[1]==="top"?"0":"auto",i.style.bottom=r.banner.position.split("-")[1]==="bottom"?"0":"auto",i.style.left=r.banner.position.split("-")[0]==="left"?"0":"auto",i.style.right=r.banner.position.split("-")[0]==="right"?"0":"auto",i.style.width="100%",i.style.margin="auto",i.style.backgroundColor="#f0f0f0",i.style.padding="10px",i.style.textAlign="center",i.style.zIndex="10000",i.textContent=e,document.body.appendChild(i)}static createTriggerButton(e){if(typeof window>"u")return;if(!t.experience)throw new Error("GrowthRail: Experience not loaded");t.floatingButton&&t.floatingButton.unmount();let r={...t.experience?.trigger,...e};t.floatingButton=new v(r),t.floatingButton.mount()}static destroyTriggerButton(){t.floatingButton&&(t.floatingButton.unmount(),t.floatingButton=null)}};a(t,"api"),a(t,"storage"),a(t,"options"),a(t,"currentUser",null),a(t,"initialized",!1),a(t,"referralModal",null),a(t,"floatingButton",null),a(t,"experience",null),a(t,"userReadyPromise",null),a(t,"userReadyResolver",null);var m=t;0&&(module.exports={GrowthRail,ReferralModal});
|
|
876
17
|
//# sourceMappingURL=index.js.map
|