Created
June 17, 2017 12:04
-
-
Save timReynolds/3360580163e21d283052541f1c62e84c to your computer and use it in GitHub Desktop.
Segment.com with next.js
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
<Head> | |
<script dangerouslySetInnerHTML={{ __html: ` | |
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"];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){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="4.0.0"; | |
analytics.load("t65z006w75");analytics.page();} | |
`}} /> | |
</Head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@archywillhe @timReynolds I'm not sure the
with-segment-analytics
example is best practices. I'm experimenting and looking deeper into this and determined to get this right (mostly because I used to work at Segment and currently implementing it in my nextjs app so take pride in ensuring it's correct and consistent for others to use).For now, here is a detailed comment I left on an open issue about my findings: vercel/next.js#11535 (comment)