Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Snippet doesn't work with JSX #34

Open
ian opened this issue May 14, 2020 · 3 comments
Open

Snippet doesn't work with JSX #34

ian opened this issue May 14, 2020 · 3 comments

Comments

@ian
Copy link

ian commented May 14, 2020

We really need a React-based approach to this library, the snippet that is assigned in the project's config will fail JSX formatting rules.

Either segment should update their global script tag snippet, or this library should provide a JSX friendly way to implement Segment.

  42 |           <script type="text/javascript">
> 43 |             !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"];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://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";
     |                         ^
  44 |             analytics.load("YOUR_WRITE_KEY");
  45 |             // analytics.page() // Uncomment if your application is NOT an SPA
  46 |             }}();
AMP bind syntax []='' is not supported in JSX, use 'data-amp-bind-' instead. https://err.sh/zeit/next.js/amp-bind-jsx-alt

@devinhalladay
Copy link

+1, but in the meantime, you can use dangerouslySetInnerHTML

@bscaspar
Copy link

I encountered the same thing, check out this issue for my workaround.

@johanjmoncada
Copy link

johanjmoncada commented Apr 14, 2021

You all could include the snippet on the index.html of the app. I mean the file where you have the div root.

This is also true for any other script that needs to be added on the page head of just before the close body tag.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants