-
Notifications
You must be signed in to change notification settings - Fork 5
/
gatsby-browser.tsx
47 lines (40 loc) · 1.54 KB
/
gatsby-browser.tsx
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
import * as React from 'react';
// normalize CSS across browsers
import './src/normalize.css';
// custom CSS styles
import './src/highlighting-atom-one-dark.css';
// global css
import './src/style.less';
// Highlighting for code blocks
// import "prismjs/themes/prism.css"
import WrapPageElementComponent from './src/components/WrapPageElementComponent';
export const wrapPageElement = ({ element }) => (
<WrapPageElementComponent>{element}</WrapPageElementComponent>
);
// Copied from https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-google-gtag/src/gatsby-browser.js
export const onRouteUpdate = ({ location, prevLocation }) => {
if (
process.env.NODE_ENV !== 'production' ||
typeof window.gtag !== 'function' ||
// Check this to prevent this call from being fired on load of the page
!prevLocation
) {
return null;
}
// wrap inside a timeout to make sure react-helmet is done with its changes (https://github.com/gatsbyjs/gatsby/issues/11592)
const sendPageView = () => {
const pagePath = location
? location.pathname + location.search + location.hash
: undefined;
window.gtag('event', 'page_view', { page_path: pagePath });
};
if ('requestAnimationFrame' in window) {
requestAnimationFrame(() => {
requestAnimationFrame(() => setTimeout(sendPageView, 0));
});
} else {
// Delay by 32ms to simulate 2 requestOnAnimationFrame calls
setTimeout(sendPageView, 32);
}
return null;
};