Skip to content

Commit 7fd60fe

Browse files
committed
DS-743: Add heap script on production.
1 parent 51b6bd2 commit 7fd60fe

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

gatsby-config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ const path = require('path');
22

33
require('dotenv').config();
44

5-
const activeEnv =
6-
process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || 'development';
7-
85
// Support for Gatsby CLI
96
let siteUrl = 'http://localhost:8000';
107

gatsby-ssr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*/
66

77
import SearchOverlayProvider from './src/context/searchOverlayStatusProvider';
8-
export const wrapRootElement = SearchOverlayProvider;
8+
export const wrapRootElement = SearchOverlayProvider;

src/components/partials/htmlHead.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import React from 'react';
22

33
/*
44
** The HtmlHead component is included into the html.js file, to always be loaded.
5-
* The purpose of this file is to provide a default Title value,
6-
* ensure that favicons are provided from Stanford's media source, particularly for browser tab and phone home screens.
75
*/
86

97
const HtmlHead = () => {
8+
// Heap ID
9+
const ID = '2306378928';
10+
const isProduction = process.env.CONTEXT === 'production';
11+
1012
return (
1113
<>
1214
<link
@@ -104,6 +106,15 @@ const HtmlHead = () => {
104106
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"
105107
rel="stylesheet"
106108
/>
109+
{isProduction && (
110+
<script
111+
id="heap-id"
112+
dangerouslySetInnerHTML={{
113+
__html: `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+
/>
117+
)}
107118
</>
108119
);
109120
};

0 commit comments

Comments
 (0)