Skip to content

Enable analytics on v1 DAO-57 - #1556

Merged
yuetloo merged 5 commits into
masterfrom
Enable-analytics-on-v1_DAO-57
Jul 15, 2021
Merged

yuetloo merged 5 commits into
masterfrom
Enable-analytics-on-v1_DAO-57

Conversation

@Rekard0

@Rekard0 Rekard0 commented Jul 14, 2021 •

Copy link
Copy Markdown
Contributor
  • Enable segment analytics
  • 2 test event is implemented
  • track pages
  • track user identification

important: REACT_APP_ANALYTICS_KEY with aproperate key needs to be set on deployment

Comment thread src/App.js Outdated
// analytics
if (process.env.REACT_APP_ANALYTICS_KEY) {
const script = document.createElement('script')
script.innerText = `!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methods[e];analytics[key]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics._writeKey="${process.env.REACT_APP_ANALYTICS_KEY}";analytics.SNIPPET_VERSION="4.13.2";analytics.load("${process.env.REACT_APP_ANALYTICS_KEY}");}}();`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if this goes to the index.html file like the helpscout stuff was done?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but we have 2 different key that we need to access it from the .env,
the app is not set to access .env from index.html
so i was thinking we could access the env at react level and inject the script once app is mounted

Comment thread src/routing.js Resolved
@yuetloo
yuetloo merged commit fafccce into master Jul 15, 2021
@yuetloo
yuetloo deleted the Enable-analytics-on-v1_DAO-57 branch July 15, 2021 15:44

This branch was successfully deployed

1 active deployment
Preview — 0bbf61f3 Deployed Jul 15, 2021 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants