-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-browser.js
32 lines (27 loc) · 946 Bytes
/
gatsby-browser.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
"use strict";
exports.__esModule = true;
exports.onInitialClientRender = void 0;
const onInitialClientRender = (_, pluginOptions) => {
const tawkId = pluginOptions.tawkId;
const delayLoad = pluginOptions.optimize;
const source = "https://embed.tawk.to/" + tawkId + "/default";
const tawkScript = document.createElement("script");
tawkScript.src = source;
tawkScript.defer = true;
const reffererMeta = document.createElement("meta");
reffererMeta.name = "referrer";
reffererMeta.content = "no-referrer-when-downgrade";
const appendScript = () => {
document.head.appendChild(reffererMeta);
document.body.appendChild(tawkScript);
};
if (!delayLoad) {
appendScript();
} else {
setTimeout(() => {
window["requestIdleCallback"] ? window.requestIdleCallback(appendScript) : appendScript();
console.log("added script");
}, 3000);
}
};
exports.onInitialClientRender = onInitialClientRender;