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

console error Uncaught SyntaxError: Unexpected token < #20

Closed
A11oW opened this issue Apr 4, 2016 · 8 comments
Closed

console error Uncaught SyntaxError: Unexpected token < #20

A11oW opened this issue Apr 4, 2016 · 8 comments

Comments

@A11oW
Copy link

A11oW commented Apr 4, 2016

Hello. Thanks for component, but I have error in console, when I try use his.
error in this line eval(gtmScriptNode.textContent);

error happens because gtmScriptNode.textContent have html tags

maybe eval only script content?
const gtmScriptNode = document.getElementById(scriptId).getElementsByTagName('script')[0]

@A11oW A11oW changed the title console error SyntaxError: Unexpected token < console error Uncaught SyntaxError: Unexpected token < Apr 4, 2016
@FQ400
Copy link
Contributor

FQ400 commented Apr 5, 2016

Hi @A11oW, I will check you issue tomorrow and come back to you.

@cidevant
Copy link

cidevant commented Apr 9, 2016

In README author shows us how to use react-gtm. If you "blind" copied it - bug might be hidden here.
Look closely to render method:

      <div id={scriptId || 'react-google-tag-manager-gtm'}>
        {gtm.noScriptAsReact()}
        {gtm.scriptAsReact()}
      </div>

You see that on the first place is called method gtm.noScriptAsReact(), which does nothing, when client browsering web with enabled js. On the server it renders <iframe> and then client's browser is trying to js eval this <iframe> - big bada boom!)

Maybe this error wont happen, if your app is not isomorphic.

Cheers.

@cidevant
Copy link

cidevant commented Apr 9, 2016

Maybe this piece of code can help you) Just edit your render method like this

    return (
      <div>
        <div>{gtm.noScriptAsReact()}</div>
        <div id={scriptId || 'react-google-tag-manager-gtm'}>
          {gtm.scriptAsReact()}
        </div>
      </div>
    );

@diffractometer
Copy link

+1 @cidevant, but I had to use this.props.scriptId

    return (
      <div>
        <div>{gtm.noScriptAsReact()}</div>
        <div id={this.props.scriptId || 'react-google-tag-manager-gtm'}>
          {gtm.scriptAsReact()}
        </div>
      </div>
    );

@cidevant
Copy link

@diffractometer You are right :) I used this before return method:

const { scriptId } = this.props;

@positivew
Copy link

I also stumbled upon this problem. Could you update the example in README to be like @cidevant suggested?

FQ400 pushed a commit that referenced this issue Jun 13, 2016
@gf3
Copy link

gf3 commented Jun 13, 2016

wouldn't it be cleaner to use a ref instead of an id?

@FQ400
Copy link
Contributor

FQ400 commented Jun 14, 2016

I think this depends on your use case.

@FQ400 FQ400 closed this as completed in fcb54cf Jun 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants