Skip to content

Commit ff88f52

Browse files
committed
For test.
1 parent 0984300 commit ff88f52

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

gatsby-browser.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import React from 'react';
2+
import { Script } from 'gatsby';
3+
14
/**
25
* Implement Gatsby's Browser APIs in this file.
36
*
@@ -20,3 +23,27 @@ export const shouldUpdateScroll = ({ routerProps: { location } }) => {
2023
return false;
2124
}
2225
};
26+
27+
/**
28+
* Add Heap Analytics script to the site.
29+
*/
30+
export const wrapPageElement = ({ element }) => {
31+
const ID = '2306378928';
32+
33+
// Only load on production.
34+
if (!process.env.CONTEXT || process.env.CONTEXT !== 'deploy-preview') {
35+
return element;
36+
}
37+
38+
return (
39+
<>
40+
<Script id="heap-id">
41+
{`
42+
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);for(var n=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],o=0;o<p.length;o++)heap[p[o]]=n(p[o])};
43+
heap.load(${ID});
44+
`}
45+
</Script>
46+
{element}
47+
</>
48+
);
49+
};

gatsby-ssr.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
1+
import React from 'react';
2+
import { Script } from 'gatsby';
3+
14
/**
25
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
36
*
47
* See: https://www.gatsbyjs.org/docs/ssr-apis/
58
*/
69

710
import SearchOverlayProvider from './src/context/searchOverlayStatusProvider';
8-
export const wrapRootElement = SearchOverlayProvider;
11+
export const wrapRootElement = SearchOverlayProvider;
12+
13+
/**
14+
* Add Heap Analytics script to the site.
15+
*/
16+
export const wrapPageElement = ({ element }) => {
17+
const ID = '2306378928';
18+
19+
// Only load on production.
20+
if (!process.env.CONTEXT || process.env.CONTEXT !== 'deploy-preview') {
21+
return element;
22+
}
23+
24+
return (
25+
<>
26+
<Script id="heap-id">
27+
{`
28+
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);for(var n=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],o=0;o<p.length;o++)heap[p[o]]=n(p[o])};
29+
heap.load(${ID});
30+
`}
31+
</Script>
32+
{element}
33+
</>
34+
);
35+
};

src/components/partials/htmlHead.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import React from 'react';
22
import { Script } from 'gatsby';
33

4-
/**
5-
* Heap Analytics script
6-
*/
7-
const ID = '2306378928';
8-
94
/*
105
** The HtmlHead component is included into the html.js file, to always be loaded.
116
*/
127

138
const HtmlHead = () => {
9+
// Heap ID
10+
const ID = '2306378928';
11+
1412
return (
1513
<>
1614
<link
@@ -108,13 +106,6 @@ const HtmlHead = () => {
108106
href="https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&family=Source+Serif+4:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap"
109107
rel="stylesheet"
110108
/>
111-
<Script id="heap-id" strategy="post-hydrate">
112-
{`
113-
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);for(var n=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],o=0;o<p.length;o++)heap[p[o]]=n(p[o])};
114-
heap.load(${ID});
115-
`}
116-
</Script>
117-
<meta name="postheap" content="true" />
118109
</>
119110
);
120111
};

0 commit comments

Comments
 (0)