# Install on Any HTML Site

Canonical: https://sourcetag.io/docs/install-html

If your site isn't built on WordPress, Webflow, Squarespace, or another platform with a dedicated guide, you can install SourceTag by adding a single script tag to your HTML.

This works for static HTML sites, custom-built sites, PHP sites, Node.js apps, and anything else that serves HTML pages.

## Step 1: Copy your script tag

In your SourceTag dashboard, go to your site's detail page and copy the script tag. It looks like this:

```html
<script src="https://cdn.sourcetag.io/scripts/YOUR_SITE_ID/st.js"></script>
```

Replace `YOUR_SITE_ID` with your actual Site ID from the dashboard.

## Step 2: Paste the script before the closing head tag

Open your site's HTML (or the template/layout file that generates every page) and paste the script tag just before the closing `</head>` tag.

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Your Site</title>
  <!-- other head elements -->

  <!-- SourceTag -->
  <script src="https://cdn.sourcetag.io/scripts/YOUR_SITE_ID/st.js"></script>
</head>
<body>
  <!-- page content -->
</body>
</html>
```

The script should be present on every page of your site, not just the page with the form.

**Why every page?** SourceTag needs to read the URL parameters and referrer on whichever page the visitor lands on. If the script only runs on your contact page, you'll miss attribution data from visitors who land on other pages first.

## Step 3: Add hidden fields to your forms

SourceTag does not create hidden fields - it only populates fields that already exist in your form. You need to add the hidden fields yourself.

Add hidden input elements inside your form:

```html
<form action="/submit" method="POST">
  <!-- Your visible fields -->
  <input type="text" name="name" placeholder="Your name" required>
  <input type="email" name="email" placeholder="Your email" required>
  <textarea name="message" placeholder="Your message"></textarea>

  <!-- SourceTag core hidden fields -->
  <input type="hidden" name="st_fc_channel">
  <input type="hidden" name="st_fc_detail_1">
  <input type="hidden" name="st_fc_detail_2">
  <input type="hidden" name="st_fc_detail_3">
  <input type="hidden" name="st_fc_detail_4">
  <input type="hidden" name="st_lc_channel">
  <input type="hidden" name="st_lc_detail_1">
  <input type="hidden" name="st_lc_detail_2">
  <input type="hidden" name="st_lc_detail_3">
  <input type="hidden" name="st_lc_detail_4">
  <input type="hidden" name="st_fc_landing_page">
  <input type="hidden" name="st_lc_landing_page">

  <button type="submit">Send</button>
</form>
```

Leave the `value` attributes empty. SourceTag finds these fields by their `name` attribute and fills in the values automatically. The `st_fc_channel` field must be present or the form will be skipped entirely.

See [Add Hidden Fields to HTML Forms](https://sourcetag.io/docs/fields-html) for the full list of available fields including optional extended fields.

## Step 4: Test with UTM parameters

Visit your site with test UTM parameters appended to the URL:

```text
https://yoursite.com/?utm_source=test&utm_medium=cpc&utm_campaign=html-install-test
```

Open your browser's developer tools (F12 or Cmd+Option+I on Mac) and check the following:

1. **Script loaded:** In the Network panel, filter for `st.js`. It should show a 200 status.
2. **Cookie set:** In Application > Cookies, look for `_sourcetag` on your domain.
3. **Hidden fields populated:** In the Elements panel, find your form and expand it. You should see hidden inputs with values like `st_fc_channel = Paid Search`.

Submit the form and check wherever submissions are received (email notification, server logs, CRM) to confirm the attribution data came through.

See [Testing SourceTag](https://sourcetag.io/docs/testing) for a detailed testing walkthrough.

## Common setups

### Static site generators (Hugo, Jekyll, Eleventy, Astro)

Add the script tag to your base layout template. In most static site generators, this is a file like `base.html`, `_default.html`, or `Layout.astro` that wraps every page.

### PHP sites

Add the script tag to your header include file (commonly `header.php` or `includes/head.php`).

### Server-rendered apps (Express, Django, Rails, Laravel)

Add the script tag to your main layout template that renders the `<head>` section.

## Troubleshooting

**Script returns 404:** Make sure you have added your site in the SourceTag dashboard.

**Cookie not being set:** Check the browser console for errors. If another script on the page is throwing an error before SourceTag runs, it could interfere (though this is uncommon).

**Hidden fields not appearing:** Make sure you have added the hidden fields to your form (SourceTag only populates existing fields, it does not create them). Verify the form uses a standard `<form>` HTML element or an element with class `.form`.
