I want to install my tracking code. I can’t alter the HTML directly, so I’m injecting the code with JavaScript. The script tags get appended to the body, but they aren’t working; the browser is throwing a CORS error. What might be causing the block?
HI @APW the tracking code needs to be added to the <head> tag, so being appended to the <body> is likely what is causing the error.
According to installation guide, “To install the tracking code, paste the code before the closing </body> tag.” But whether I append it to the head or body, I get the same error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://forms.hubspot.com/collected-forms/v1/config/json?portalId=…
Basically, the browser doesn’t like that the origin of the file is different from your website.
There are two choices to resolve a CORS error:
1 - move the resource to the same domain (not an option in this case)
2 - enable CORS in your browser, for example this option for chrome, or add a plugin for CORS to WordPress, like this one
I’m not sure if you’re encountering this issue because you’re injecting the code via javascript rather than editing the head directly, but if you Google your browser and/or CMS, with CORS error, you’ll find available resources to resolve the error