-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-ssr.js
More file actions
45 lines (41 loc) · 1.65 KB
/
gatsby-ssr.js
File metadata and controls
45 lines (41 loc) · 1.65 KB
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
// Import React so that you can use JSX in HeadComponents
const React = require("react");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
exports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {
const headComponents = getHeadComponents();
headComponents.unshift(React.createElement("meta", { name: "segment-key", content: "", key: "segment-key" }));
replaceHeadComponents(headComponents);
};
exports.onRenderBody = function ({ setHeadComponents }, pluginOptions) {
var redditSnippet =
"!function(w,d){var p=w.rdt=function(){p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments)};p.callQueue=[];var t=d.createElement('script');t.src='https://www.redditstatic.com/ads/pixel.js',t.async=!0;var s=d.getElementsByTagName('script')[0];s.parentNode.insertBefore(t,s)}(window,document);";
const loadSnippet =
`window.redditSnippetLoaded = false;
(function(w) {
const delayedEvents = [];
w.rdt = function() {
delayedEvents.push(arguments);
}
w.redditSnippetLoader = function (id, callback) {
if (!w.redditSnippetLoaded) {
w.redditSnippetLoaded = true;
` +
redditSnippet +
`
rdt('init',id);
for (var i = 0; i < delayedEvents.length; i++) {
rdt.apply(null, delayedEvents[i]);
}
if (callback) callback();
}
}
})(window);`;
setHeadComponents([
React.createElement("script", {
key: "reddit-pixel",
dangerouslySetInnerHTML: { __html: loadSnippet },
}),
]);
};