-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added trackig of page views. * Added moment play/pause event tracking. * Switched to double quoted strings. * Fixed a linting error. * Started tracking play time with periodic events. * Minor improvements. * Better throttling for GA events * Added Google Analytics as a webpack external. * Moved Google Analytics initialization code to the header. * Made Google Analytics configurable.
- Loading branch information
1 parent
fb656ee
commit 08463c1
Showing
9 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// development config | ||
export default {}; | ||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// production config | ||
export default { | ||
apiEntry: "https://explore-apollo-api.herokuapp.com" | ||
module.exports = { | ||
apiEntry: "https://explore-apollo-api.herokuapp.com", | ||
GoogleAnalyticsCode: "UA-83921870-1" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// staging config | ||
export default { | ||
apiEntry: "https://exploreapollo-api-staging.herokuapp.com" | ||
module.exports = { | ||
apiEntry: "https://exploreapollo-api-staging.herokuapp.com", | ||
GoogleAnalyticsCode: "UA-83921870-1" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { RECEIVE_AUDIO } from "./actions"; | ||
import {throttle, isFunction} from "lodash"; | ||
import ga from "ga"; | ||
|
||
// Tracks page-views and audio play times. | ||
export function googleAnalytics(store) { | ||
// This constant isn't exported from redux-router so I'm having to redefine it. | ||
// It's a bit of a hack and makes the Google Analytics code dependent on redux-router's internal implementation. | ||
// The better way to do this is to subscribe to the react router using browserHistory, | ||
// but redux and redux-router make it difficult to access browswerHistory in a middleware function.. | ||
const ROUTER_DID_CHANGE = "@@reduxReactRouter/routerDidChange"; | ||
|
||
const gaMomentEventCategory = "Moment"; | ||
const gaPlayTimeEventAction = "playTime"; | ||
const gaPlayTimeEventIntervalInMilliseconds = 5000; | ||
|
||
// Some helper functions. | ||
const sendPlayTimeEvent = throttle(function(playTimeInMilliseconds) { | ||
if (isFunction(ga)) { | ||
ga("send", "event", gaMomentEventCategory, gaPlayTimeEventAction, store.getState().audio.momentId, playTimeInMilliseconds); | ||
} | ||
}, gaPlayTimeEventIntervalInMilliseconds); | ||
|
||
// Return a function handling actions. | ||
return next => action => { | ||
switch (action.type) { | ||
case ROUTER_DID_CHANGE: | ||
// Send a page-view. | ||
if (isFunction(ga)) { | ||
ga("set", "page", action.payload.location.pathname + action.payload.location.search); | ||
ga("send", "pageview"); | ||
} | ||
|
||
break; | ||
case RECEIVE_AUDIO: | ||
const isPlaying = !!store.getState().audio.playing || !!action.playing; | ||
if (isPlaying && action.time) { | ||
// Audio has started playing, so start sending play time events. | ||
sendPlayTimeEvent(action.time); | ||
} | ||
|
||
break; | ||
} | ||
|
||
return next(action); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters