Wrap sprig init in check for window

This commit is contained in:
James Grugett 2022-10-06 15:23:51 -05:00
parent 91da39370f
commit 4162cca3ff

View File

@ -5,7 +5,7 @@
import { ENV_CONFIG } from 'common/envs/constants' import { ENV_CONFIG } from 'common/envs/constants'
import { PROD_CONFIG } from 'common/envs/prod' import { PROD_CONFIG } from 'common/envs/prod'
if (ENV_CONFIG.domain === PROD_CONFIG.domain) { if (ENV_CONFIG.domain === PROD_CONFIG.domain && typeof window !== 'undefined') {
try { try {
;(function (l, e, a, p) { ;(function (l, e, a, p) {
if (window.Sprig) return if (window.Sprig) return
@ -20,7 +20,8 @@ if (ENV_CONFIG.domain === PROD_CONFIG.domain) {
a.async = 1 a.async = 1
a.src = e + '?id=' + S.appId a.src = e + '?id=' + S.appId
p = l.getElementsByTagName('script')[0] p = l.getElementsByTagName('script')[0]
p.parentNode.insertBefore(a, p) ENV_CONFIG.domain === PROD_CONFIG.domain &&
p.parentNode.insertBefore(a, p)
})(document, 'https://cdn.sprig.com/shim.js', ENV_CONFIG.sprigEnvironmentId) })(document, 'https://cdn.sprig.com/shim.js', ENV_CONFIG.sprigEnvironmentId)
} catch (error) { } catch (error) {
console.log('Error initializing Sprig, please complain to Barak', error) console.log('Error initializing Sprig, please complain to Barak', error)