All Collections
Site analytics
Analytics
Adding analytics scripts to your site
Adding analytics scripts to your site

How to add your custom analytics scripts to individual sites

Ashmita Taneja avatar
Written by Ashmita Taneja
Updated over a week ago

Custom analytics scripts can be added to your Zoomforth sites through the "Site Scripts" feature. This is an advanced feature intended for people who feel comfortable with JavaScript code.

Ensure "Site Scripts" is active for your account.

You must request the "site scripts" feature for your account. You can see whether the feature is active by opening the site details page for a site and selecting the More tab. If the "Site Scripts" option is visible that means that the feature is active for your account.

You may request this feature by contacting support.


Adding and updating scripts

When adding a script make sure the JavaScript code is enclosed in a <script> tag. 

<script>
  alert('Running script 1')
</script>
<script>
  alert('Running script 2')
</script>

All scripts will be inserted at the end of the <head> tag. 

Only the <script> HTML tag is supported. If you save any other tags they might appear as text on your site. Double check that this is not the case after saving your scripts.

If you add multiple scripts it is recommended to put each script in its own <script> tag. All scripts will be run on every site load.

This feature is intended for analytics scripts and while other scripts can be run that is not recommended.

Warning: Site updates immediately upon save

Immediately upon clicking "save", your site will be updated with the new script. (There is no "publishing" needed.)

Make sure nothing is broken!

Please be aware that a faulty script could potentially break your site for visitors so make sure to double check your scripts before saving, and also confirm that the site is working properly after saving.

Note: Site Scripts only run on published sites

Site scripts only run on published sites. They do not run on site preview; they do not run in the site editor.

This is because site scripts are intended mostly for analytics purposes. We highly recommend you do not attempt to make changes to site contents or styling using this feature.

<!-- DONT DO THIS -->
<script>
  // These scripts only runs on published sites, so these style
  // changes won't appear in preview or the editor
  var body = document.getElementsByTagName('body')[0];
  body.style.backgroundColor = 'red';
</script>
<!-- DONT DO THIS -->

Creating a site script requires considerable knowledge of scripting techniques. It's important to note that scripting development and troubleshooting fall outside our support scope and should be undertaken with caution. A faulty script can swiftly disrupt the site for visitors. We strongly recommend creating a duplicate of your site as a backup before implementing any site script.

Did this answer your question?