-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React-GA (Google Analytics) throwing errors on build #412
Comments
When Gatsby builds a site it's not running in a browser so the The easiest work-around is to require the component in |
Hello again! While trying out the method you brought up on twitter, which worked perfectly during development, I appeared to run into some sort of issue with the formatting of the block that delineates the GA script: Here's how I've gone about implementing it (note this is an import React from 'react'
import DocumentTitle from 'react-document-title'
import { prefixLink } from 'gatsby-helpers'
import { TypographyStyle } from 'utils/typography'
const BUILD_TIME = new Date().getTime()
module.exports = React.createClass({
displayName: 'HTML',
propTypes: {
body: React.PropTypes.string,
},
render () {
const { body } = this.props
const title = DocumentTitle.rewind()
let css
if (process.env.NODE_ENV === 'production') {
css = <style dangerouslySetInnerHTML={{ __html: require('!raw!./public/styles.css') }} />
}
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0 maximum-scale=5.0"
/>
<title>{title}</title>
<TypographyStyle />
{css}
</head>
<body className="landing-page">
<div id="react-mount" dangerouslySetInnerHTML={{ __html: body }} />
<script src={prefixLink(`/bundle.js?t=${BUILD_TIME}`)} />
{scripts}
<script dangerouslySetInnerHTML={{__html: """
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-59560755-1', 'auto');
ga('send', 'pageview');
"""}}
/>
</body>
</html>
)
},
}) This file caused the issue seen here, while I attempted to build the site:
It's looking like the """ which are supposed to delineate the script doesn't seem to be recognized at all. For kicks, I tried renaming the file
|
Ooo yeah. That's a diff between coffeescript and JavaScript. For multi line
|
Hello! Right now I'm being thrown the following errors after installing the React-GA npm module:
This is after installing the module via npm and importing it into my root index.js file as so:
Do you happen to have any direct idea as to why this would throw errors on build? While in develop mode everything appears to work fine, and while viewing source, I definitely see the intact GA script included at the end of the page.
Thanks!
The text was updated successfully, but these errors were encountered: