Skip to content

Commit

Permalink
Merge pull request #212 from suitupalex/feature/ga-prod
Browse files Browse the repository at this point in the history
Base, Router, ContentManager, server: Google Analytics + Production Contentful
  • Loading branch information
umamialex authored Jun 18, 2016
2 parents 376ca8e + cf78046 commit 7fa5476
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
2 changes: 2 additions & 0 deletions backend/ContentManager/ContentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ContentManager {
, host: options.isProduction ? undefined : 'preview.contentful.com'
})

this.log('Production environment:', options.isProduction)

this.entryReducer = this.entryReducer.bind(this)

this.fetchInterval = options.fetchInterval
Expand Down
3 changes: 2 additions & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const HttpServer = require('./HttpServer/HttpServer')

const contentManager = new ContentManager({
accessToken: env.CONTENTFUL_ACCESS_TOKEN
, log: log.contentManager
, fetchInterval:
parseFloat(env.FETCH_INTERVAL ? env.FETCH_INTERVAL : 30) * 60000
, isProduction: env.NODE_ENV === 'production'
, log: log.contentManager
, space: env.CONTENTFUL_SPACE
})

Expand Down
30 changes: 15 additions & 15 deletions dist/base.bundle.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions frontend/Base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import ReactDOM from 'react-dom'

import App from './App/App.jsx'

(function(i,s,o,g,r,a,m){
i['GoogleAnalyticsObject'] = r
i[r] = i[r] || function ga() {
(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'
)

window.ga('create', 'UA-53849837-1', 'auto')

ReactDOM.render(
<App url={`${process.env.URL}`}/>
, document.body.querySelector('#app')
Expand Down
12 changes: 11 additions & 1 deletion frontend/Router/Router.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ class Router extends React.Component {
log('Parsing route:', raw)

const parsed = urlParse(raw, true)
const route = _.compact(parsed.pathname.split('/'))

const out = {
route: _.compact(parsed.pathname.split('/'))
route
, query: parsed.query
}

log('Parsed route to:', out)

this.updateGa(`/${route.join('/')}`)

return out
}

Expand All @@ -72,6 +75,13 @@ class Router extends React.Component {
this.setState(parsed)
}

updateGa(route) {
log('Updating GA:', route)

window.ga('set', 'page', route)
window.ga('send', 'pageview')
}

handlePopState() {
log('Handling popped state:', window.location.href)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "suitupalex.com",
"version": "1.0.0",
"version": "1.0.1",
"description": "Source code for suitupalex.com.",
"scripts": {
"build": "./scripts/build",
Expand Down

0 comments on commit 7fa5476

Please sign in to comment.