Skip to content
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

Enable analytics on v1 DAO-57 #1556

Merged
merged 5 commits into from
Jul 15, 2021
Merged

Enable analytics on v1 DAO-57 #1556

merged 5 commits into from
Jul 15, 2021

Conversation

Rekard0
Copy link
Contributor

@Rekard0 Rekard0 commented Jul 14, 2021

  • 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

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
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
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

src/routing.js Outdated Show resolved Hide 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
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