-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (45 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Next Snapchat Pixel Module
*
* @package next-snapchat-pixel
* @author Kamal Mirzayev <mirzayevkamal@gmail.com>
*
**/
var initialized = false;
export default {
init(pixelId) {
if (!pixelId) {
console.warn('Please, insert pixel ID to initialize');
} else {
if (window !== undefined) {
(function (e, t, n) {
if (e.snaptr) return;
var a = e.snaptr = function () {
a.handleRequest ? a.handleRequest.apply(a, arguments) : a.queue.push(arguments);
};
a.queue = [];
const s = 'script';
const r = t.createElement(s); r.async = !0; r.src = n;
const u = t.getElementsByTagName(s)[0];
u.parentNode.insertBefore(r, u);
}(window, document, 'https://sc-static.net/scevent.min.js'));
snaptr('init', pixelId);
initialized = true;
} else {
console.error('Window is not defined')
}
}
},
track(type) {
if (!initialized) {
console.warn('Can not track before initializing.')
}
snaptr('track', type);
},
trackWithData(type, data) {
if (!initialized) {
console.warn('Can not track before initializing.')
}
snaptr('track', type, data);
}
}