Repository navigation
Enable analytics on v1 DAO-57 - #1556
Merged
Merged
Conversation
yuetloo
reviewed
Jul 14, 2021
| // 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}");}}();` |
Contributor
There was a problem hiding this comment.
wonder if this goes to the index.html file like the helpscout stuff was done?
Contributor
Author
There was a problem hiding this comment.
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
yuetloo
approved these changes
Jul 15, 2021
This branch was successfully deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
important: REACT_APP_ANALYTICS_KEY with aproperate key needs to be set on deployment