-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.js
35 lines (28 loc) · 961 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
33
34
35
import React from 'react';
import PageElement from './src/components/page/page-element';
import RootElement from './src/components/page/root-element';
import './src/styles/global.css';
export const onRouteUpdate = ({ location }) => {
const element = document.getElementById(location.hash.split('#')[1]?.toLowerCase());
if (element) {
window.scrollTo({
top: element.offsetTop - 80,
left: 0
});
}
if (process.env.NODE_ENV !== 'production') {
return null;
}
const pagePath = location ? location.pathname + location.search + location.hash : undefined;
setTimeout(() => {
if (typeof window.gtag === 'function') {
window.gtag('event', 'page_view', { page_path: pagePath });
}
}, 100);
};
export const wrapPageElement = ({ element, props }) => {
return <PageElement {...props}>{element}</PageElement>;
};
export const wrapRootElement = ({ element }) => {
return <RootElement>{element}</RootElement>;
};