Skip to content

Commit 065b910

Browse files
committed
Don't go through segment
A. Maybe fix lack of GA referrer problem? B. Cost, and only using two destinations
1 parent 6f59e1e commit 065b910

File tree

10 files changed

+71
-16
lines changed

10 files changed

+71
-16
lines changed

β€Žpackage-lock.jsonβ€Ž

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"react": "^16.2.0",
3636
"react-apollo": "^2.1.3",
3737
"react-dom": "^16.3.2",
38+
"react-ga": "^2.5.3",
3839
"react-loading-skeleton": "^0.3.2",
3940
"react-markdown": "^3.3.0",
4041
"react-odometerjs": "^2.0.0",

β€Žpublic/index.htmlβ€Ž

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,9 @@
6161
To create a production bundle, use `npm run build` or `yarn build`.
6262
-->
6363

64-
<script>
65-
!function () {
66-
var analytics = window.analytics = window.analytics || []; if (!analytics.initialize) if (analytics.invoked) window.console && console.error && console.error("Segment snippet included twice."); else {
67-
analytics.invoked = !0; analytics.methods = ["trackSubmit", "trackClick", "trackLink", "trackForm", "pageview", "identify", "reset", "group", "track", "ready", "alias", "debug", "page", "once", "off", "on"]; analytics.factory = function (t) { return function () { var e = Array.prototype.slice.call(arguments); e.unshift(t); analytics.push(e); return analytics } }; for (var t = 0; t < analytics.methods.length; t++) { var e = analytics.methods[t]; analytics[e] = analytics.factory(e) } analytics.load = function (t, e) { var n = document.createElement("script"); n.type = "text/javascript"; n.async = !0; n.src = ("https:" === document.location.protocol ? "https://" : "http://") + "cdn.segment.com/analytics.js/v1/" + t + "/analytics.min.js"; var o = document.getElementsByTagName("script")[0]; o.parentNode.insertBefore(n, o); analytics._loadOptions = e }; analytics.SNIPPET_VERSION = "4.1.0";
68-
analytics.load("yLpaTOLBdUXKuWMOcJy87R2GIt5Bativ");
69-
analytics.page();
70-
}
71-
}();
64+
<script type="text/javascript">
65+
window.heap = window.heap || [], heap.load = function (e, t) { window.heap.appid = e, window.heap.config = t = t || {}; var r = t.forceSSL || "https:" === document.location.protocol, a = document.createElement("script"); a.type = "text/javascript", a.async = !0, a.src = (r ? "https:" : "http:") + "//cdn.heapanalytics.com/js/heap-" + e + ".js"; var n = document.getElementsByTagName("script")[0]; n.parentNode.insertBefore(a, n); for (var o = function (e) { return function () { heap.push([e].concat(Array.prototype.slice.call(arguments, 0))) } }, p = ["addEventProperties", "addUserProperties", "clearEventProperties", "identify", "resetIdentity", "removeEventProperty", "setEventProperties", "track", "unsetEventProperty"], c = 0; c < p.length; c++)heap[p[c]] = o(p[c]) };
66+
heap.load('3557733793');
7267
</script>
7368
</body>
7469

β€Žsrc/index.jsβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { Router } from 'react-router-dom'
55
import { createBrowserHistory } from 'history'
66
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles'
77
import { CloudinaryContext } from 'cloudinary-react'
8+
import ReactGA from 'react-ga'
89

910
import './index.css'
1011
import './lib/common.css'
11-
import './lib/logrocket'
12+
import './startup/'
1213
import registerServiceWorker from './registerServiceWorker'
1314
import App from './components/App'
1415
import { apollo, inDevelopment } from './lib/apollo'
@@ -21,7 +22,7 @@ const theme = createMuiTheme({
2122

2223
const history = createBrowserHistory()
2324
history.listen(location => {
24-
window.analytics.page(location.pathname)
25+
ReactGA.pageview(location.pathname)
2526
})
2627

2728
const render = Component => {

β€Žsrc/lib/payment.jsβ€Ž

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component } from 'react'
22
import gql from 'graphql-tag'
33

44
import { apollo } from './apollo'
5+
import track from './track'
56

67
// https://stripe.com/docs/checkout#integration-custom
78
// https://stripe.com/docs/checkout/express
@@ -90,28 +91,34 @@ export const stripeCheckout = (packageInfo, routerHistory) => {
9091

9192
// todo show spinner
9293

94+
const { key: packageName, licenses: teamLicenses } = packageInfo
95+
9396
// https://www.apollographql.com/docs/react/api/apollo-client.html#ApolloClient.mutate
9497
const response = await apollo.mutate({
9598
mutation: CHARGE_MUTATION,
9699
variables: {
97100
input: {
98-
package: packageInfo.key,
101+
package: packageName,
99102
stripeToken: id,
100-
teamLicenses: packageInfo.licenses,
103+
teamLicenses,
101104
email,
102105
addresses
103106
}
104107
}
105108
})
106109

107-
console.log(response)
108110
// todo switch to thrown error message instead of {charge: false}
109111
if (!response.data || !response.data.charge) {
110112
alert('Charge failed πŸ€·β€β™€οΈ. Please try another payment method.')
111113
return
112114
}
113115

114116
routerHistory.push('/welcome')
117+
118+
track('purchase', {
119+
packageName,
120+
teamLicenses
121+
})
115122
}
116123
})
117124
})

β€Žsrc/lib/track.jsβ€Ž

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import ReactGA from 'react-ga'
2+
import find from 'lodash/find'
3+
import defer from 'lodash/defer'
4+
5+
const EVENTS = [
6+
{
7+
name: 'purchase',
8+
category: 'User'
9+
}
10+
]
11+
12+
const track = (name, data) => {
13+
defer(() => {
14+
const event = find(EVENTS, { name })
15+
if (!event) {
16+
throw new Error('unknown event typeβ€”add it to track.js')
17+
}
18+
19+
ReactGA.event({
20+
category: event.category,
21+
action: name,
22+
...(data.package && { label: data.package })
23+
})
24+
window.heap.track(name, data)
25+
})
26+
}
27+
28+
export default track

β€Žsrc/lib/withAuth.jsβ€Ž

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import gql from 'graphql-tag'
77
import auth0 from 'auth0-js'
88
import { initAuthHelpers, login, logout } from 'auth0-helpers'
99
import LogRocket from 'logrocket'
10+
import defer from 'lodash/defer'
11+
import ReactGA from 'react-ga'
1012

1113
import { associateToken } from '../lib/payment'
1214

@@ -67,14 +69,14 @@ function withAuth(BaseComponent) {
6769
loggingIn: false
6870
}
6971

70-
this.onCreateOrUpdate()
72+
defer(this.onCreateOrUpdate)
7173
}
7274

7375
componentDidUpdate() {
7476
this.onCreateOrUpdate()
7577
}
7678

77-
onCreateOrUpdate() {
79+
onCreateOrUpdate = () => {
7880
const { currentUser } = this.props
7981
if (!currentUser) {
8082
return
@@ -92,7 +94,12 @@ function withAuth(BaseComponent) {
9294
hasPurchased
9395
}
9496

95-
window.analytics.identify(id, userData)
97+
window.heap.identify(id, 'ID')
98+
window.heap.addUserProperties(userData)
99+
ReactGA.set({
100+
id,
101+
...userData
102+
})
96103
LogRocket.identify(id, userData)
97104

98105
this.lastCurrentUser = currentUser
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ReactGA from 'react-ga'
2+
3+
ReactGA.initialize('UA-96115966-1')

β€Žsrc/startup/index.jsβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './google-analytics'
2+
// heap set up in index.html
3+
4+
import './logrocket'
File renamed without changes.

0 commit comments

Comments
Β (0)