This repository has been archived by the owner on Feb 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
/
gatsby-browser.js
71 lines (56 loc) · 1.6 KB
/
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
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
import React from "react";
import * as Sentry from "@sentry/browser";
import { IS_PRODUCTION } from "constants/env";
import { GlobalStyles } from "basics/GlobalStyles";
import Providers from "components/Providers";
// eslint-disable-next-line react/prop-types
export const wrapRootElement = ({ element }) => (
<Providers>
<GlobalStyles />
{element}
</Providers>
);
export const onInitialClientRender = () => {
if (IS_PRODUCTION) {
// Set up Sentry
Sentry.init({
dsn: "https://[email protected]/1531056",
});
// Set up Google Analytics
/* eslint-disable */
if (typeof ga === "function") {
ga("create", "UA-53373928-1", "auto");
ga("set", "anonymizeIp", true);
// We want developers.stellar.org and www.stellar.org to use the same
// session
ga("require", "linker");
ga("linker:autolink", ["www.stellar.org", "stellar.org"]);
ga("send", "pageview");
}
/* eslint-enable */
}
};
const isApiReference = (routerProps) =>
/\/api/.test(routerProps.location.pathname);
const getTargetOffset = (hash) => {
const offsetY = 0;
const id = window.decodeURI(hash.replace("#", ""));
if (id) {
const element = document.getElementById(id);
if (element) {
return element.offsetTop - offsetY;
}
}
return null;
};
export const shouldUpdateScroll = ({ routerProps }) => {
if (isApiReference(routerProps)) {
return routerProps.location.pathname;
}
const offset = getTargetOffset(location.hash);
if (offset) {
window.scrollTo(0, offset);
return false;
}
return true;
};