# Tracking Code Installation

**URL:** <https://community.hubspot.com/t/tracking-code-installation/73557>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [January 23, 2023, 10:49pm UTC](https://community.hubspot.com/t/tracking-code-installation/73557 "2023-01-23T22:49:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![APW](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@APW](https://community.hubspot.com/u/APW)\
**Post date:** [January 23, 2023, 10:49pm UTC](https://community.hubspot.com/t/tracking-code-installation/73557/1 "2023-01-23T22:49:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [January 23, 2023, 11:53pm UTC](https://community.hubspot.com/t/tracking-code-installation/73557/2 "2023-01-23T23:53:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![APW](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@APW](https://community.hubspot.com/u/APW)\
**Post date:** [January 24, 2023, 4:29pm UTC](https://community.hubspot.com/t/tracking-code-installation/73557/3 "2023-01-24T16:29:16Z")

</div>

According to [installation guide](https://knowledge.hubspot.com/reports/install-the-hubspot-tracking-code), “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=](https://forms.hubspot.com/collected-forms/v1/config/json?portalId=23850002&utk=)…

---

<div class="post-metadata">

**Author:** ![jnix284](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jnix284/32/29_2.png) [@jnix284](https://community.hubspot.com/u/jnix284)\
**Post date:** [January 24, 2023, 5:09pm UTC](https://community.hubspot.com/t/tracking-code-installation/73557/4 "2023-01-24T17:09:23Z")

</div>

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,](https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf) or add a plugin for CORS to WordPress, [like this one](https://wordpress.org/plugins/lh-multisite-cors/)

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
