-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk-cafe24.js
133 lines (125 loc) · 4.98 KB
/
sdk-cafe24.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(
function (global, document) {
var w = global;
if (w.GentooIO) {
return w.console.error("GentooIO script included twice");
};
// Function to inject CSS
function injectCSS(href) {
// Check if the CSS is already injected
var existingLink = document.querySelector('link[href="' + href + '"]');
if (existingLink) {
return;
}
var link = document.createElement("link");
link.rel = "stylesheet";
link.href = href;
link.type = "text/css";
link.onload = function() {
console.log("GentooIO CSS loaded successfully.");
};
link.onerror = function() {
console.error("Failed to load GentooIO CSS.");
};
document.head.appendChild(link);
}
// Inject the CSS automatically
injectCSS("https://d32xcphivq9687.cloudfront.net/floating-button-sdk-cafe24.css");
// injectCSS('./floating-button-sdk-cafe24.css');
var fb = null;
var ge = function () {
ge.c(arguments);
};
ge.q = [];
ge.c = function (args) {
ge.q.push(args)
};
ge.process = function (args) {
var method = args[0];
var params = args[1];
const parsedUrl = new URL(window.location.href);
const pathSegments = parsedUrl.pathname.split('/');
const transitionPage = '/' + pathSegments[1];
const searchParams = new URLSearchParams(window.location.search);
const utm = { utms: searchParams.get('utm_source'), utmm: searchParams.get('utm_medium'), utmcp: searchParams.get('utm_campaign'), utmct: searchParams.get('utm_content'), utmt: searchParams.get('utm_term'), tp: transitionPage };
params = { ...params, utm };
// Allow boot method anytime
if (method === 'boot') {
try {
fb = new w.FloatingButton(params);
} catch (error) {
console.error('Failed to create FloatingButton instance:', error);
}
return;
}
// For all other methods, ensure FloatingButton instance exists
if (!fb) {
console.error('GentooIO: Must call boot() before using this method');
return;
}
// Process other methods
switch (method) {
case 'init':
if (typeof fb.init === 'function') {
Promise.resolve(fb.init()).catch(error => {
console.error('Failed to initialize GentooIO:', error);
});
}
break;
case 'update':
if (typeof fb.updateParameter === 'function') {
Promise.resolve(fb.updateParameter(params)).catch(error => {
console.error('Failed to update GentooIO parameters:', error);
});
}
break;
case 'unmount':
if (typeof fb.destroy === 'function') {
Promise.resolve(fb.destroy()).catch(error => {
console.error('Failed to unmount GentooIO:', error);
});
}
break;
case 'sendLog':
if (typeof fb.sendLog === 'function') {
Promise.resolve(fb.sendLog(params)).catch(error => {
console.error('Failed to send GentooIO log:', error);
});
}
break;
default:
console.error('GentooIO: Unknown method', method);
}
};
w.GentooIO = ge;
function l() {
if (w.GentooIOInitialized) { return };
w.GentooIOInitialized = true;
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://d32xcphivq9687.cloudfront.net/floating-button-sdk-cafe24.js";
s.onload = () => {
while (ge.q.length) {
var args = ge.q.shift();
ge.process(args);
};
w.addEventListener("message", ()=>{})
};
var x = document.getElementsByTagName("script")[0];
if (x.parentNode) {
x.parentNode.insertBefore(s, x)
};
};
if (document.readyState === "complete") {
l();
} else {
w.addEventListener("DOMContentLoaded", l);
w.addEventListener("load", l);
};
}
)(window, document);
GentooIO('boot', {
partnerType: 'cafe24',
})
GentooIO('init', {});