Skip to content

Commit 2f9d17d

Browse files
authored
Merge pull request #48 from smartlook/feat/esm-support
chore: add esm build
2 parents 6794bce + 6f6852c commit 2f9d17d

File tree

9 files changed

+224
-19
lines changed

9 files changed

+224
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
node_modules
1+
node_modules
2+
.idea
File renamed without changes.

dist/cjs/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/esm/index.mjs

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
const SL_NOT_INITIALIZED = 'Smartlook client is not initialized.';
2+
export default {
3+
init: function (key, params) {
4+
const w = window;
5+
if (w.smartlook) {
6+
console.warn('Smartlook client is already initialized.');
7+
return false;
8+
}
9+
w.smartlook = function () {
10+
w.smartlook.api.push(arguments);
11+
};
12+
w.smartlook.api = [];
13+
const initParams = params;
14+
let src = 'https://web-sdk.smartlook.com/recorder.js';
15+
if (initParams === null || initParams === void 0 ? void 0 : initParams.relayProxyUrl) {
16+
try {
17+
const constructedUrl = new URL('/recorder.js', initParams.relayProxyUrl);
18+
initParams.host = constructedUrl.host;
19+
src = constructedUrl.toString();
20+
}
21+
catch (e) {
22+
console.error('Smartlook init param `relayProxyUrl` is not valid. Please provide full url like `https://my-proxy-domain.com/`.');
23+
return false;
24+
}
25+
}
26+
w.smartlook('init', key, initParams);
27+
const head = window.document.getElementsByTagName('head')[0];
28+
const script = window.document.createElement('script');
29+
script.async = true;
30+
script.type = 'text/javascript';
31+
script.crossOrigin = 'anonymous';
32+
script.src = src;
33+
head.appendChild(script);
34+
return true;
35+
},
36+
identify: function (userId, props) {
37+
const w = window;
38+
if (!w.smartlook) {
39+
console.warn(SL_NOT_INITIALIZED);
40+
return false;
41+
}
42+
if (!userId) {
43+
console.warn('Smartlook - User ID must be provided');
44+
return false;
45+
}
46+
w.smartlook('identify', userId, props);
47+
return true;
48+
},
49+
anonymize: function () {
50+
const w = window;
51+
if (!w.smartlook) {
52+
console.warn(SL_NOT_INITIALIZED);
53+
return false;
54+
}
55+
w.smartlook('anonymize');
56+
return true;
57+
},
58+
track: function (eventName, props) {
59+
const w = window;
60+
if (!w.smartlook) {
61+
console.warn(SL_NOT_INITIALIZED);
62+
return false;
63+
}
64+
w.smartlook('track', eventName, props);
65+
return true;
66+
},
67+
disable: function () {
68+
const w = window;
69+
if (!w.smartlook) {
70+
console.warn(SL_NOT_INITIALIZED);
71+
return false;
72+
}
73+
w.smartlook('disable');
74+
return true;
75+
},
76+
record: function (params) {
77+
const w = window;
78+
if (!w.smartlook) {
79+
console.warn(SL_NOT_INITIALIZED);
80+
return false;
81+
}
82+
w.smartlook('record', params);
83+
return true;
84+
},
85+
getData: function (callback) {
86+
const w = window;
87+
if (!w.smartlook) {
88+
console.warn(SL_NOT_INITIALIZED);
89+
return false;
90+
}
91+
w.smartlook(callback);
92+
return true;
93+
},
94+
restart: function () {
95+
const w = window;
96+
if (!w.smartlook) {
97+
console.warn(SL_NOT_INITIALIZED);
98+
return false;
99+
}
100+
w.smartlook('restart');
101+
return true;
102+
},
103+
pause: function () {
104+
const w = window;
105+
if (!w.smartlook) {
106+
console.warn(SL_NOT_INITIALIZED);
107+
return false;
108+
}
109+
w.smartlook('pause');
110+
return true;
111+
},
112+
resume: function () {
113+
const w = window;
114+
if (!w.smartlook) {
115+
console.warn(SL_NOT_INITIALIZED);
116+
return false;
117+
}
118+
w.smartlook('resume');
119+
return true;
120+
},
121+
error: function (error) {
122+
const w = window;
123+
if (!w.smartlook) {
124+
console.warn(SL_NOT_INITIALIZED);
125+
return false;
126+
}
127+
w.smartlook('error', error);
128+
return true;
129+
},
130+
navigation: function (locationOrPath) {
131+
const w = window;
132+
if (!w.smartlook) {
133+
console.warn(SL_NOT_INITIALIZED);
134+
return false;
135+
}
136+
w.smartlook('navigation', locationOrPath);
137+
return true;
138+
},
139+
properties: function (properties) {
140+
const w = window;
141+
if (!w.smartlook) {
142+
console.warn(SL_NOT_INITIALIZED);
143+
return false;
144+
}
145+
w.smartlook('properties', properties);
146+
return true;
147+
},
148+
initialized: function () {
149+
const w = window;
150+
return !!w.smartlook;
151+
},
152+
get playUrl() {
153+
const w = window;
154+
return w.smartlook.playUrl;
155+
},
156+
get sessionId() {
157+
const w = window;
158+
return w.smartlook.sessionId;
159+
},
160+
get visitorId() {
161+
const w = window;
162+
return w.smartlook.visitorId;
163+
},
164+
get recordId() {
165+
const w = window;
166+
return w.smartlook.recordId;
167+
},
168+
get key() {
169+
const w = window;
170+
return w.smartlook.key;
171+
},
172+
get version() {
173+
const w = window;
174+
return w.smartlook.version;
175+
},
176+
};
177+
//# sourceMappingURL=index.js.map

0 commit comments

Comments
 (0)