# Testing SourceTag

Canonical: https://sourcetag.io/docs/testing

After installing SourceTag, follow these steps to confirm everything is working. You'll check four things: the script is loading, the cookie is being set, hidden fields are being populated, and form submissions contain the data.

## Step 1: Verify the script is loading

Visit your site and open the browser developer tools (F12 or Cmd+Option+I on Mac).

### Check the page source

Go to the **Elements** panel and search for `SourceTag` (Ctrl+F or Cmd+F in the Elements panel). You should find a script tag like:

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

### Check the Network panel

Open the **Network** panel, reload the page, and filter by `st.js`. You should see the script file loaded with a 200 status code.

If you see a 404 or no request at all:
- Double-check that you've pasted the script tag correctly
- Make sure you've added your site in the SourceTag dashboard
- Check that the Site ID in the script URL matches your site in the dashboard

## Step 2: Check the cookie

Visit your site with UTM parameters in the URL:

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

In developer tools, go to **Application > Cookies** (Chrome) or **Storage > Cookies** (Firefox). Look for a cookie named `_sourcetag` on your domain.

Click on the cookie to inspect its value. You should see a JSON string containing `fc` and `lc` objects with your test UTM values. The `fc.channel` should show the matched channel (e.g. "Paid Search" if you used utm_medium=cpc), and `fc.d1` should show the source value.

The channel will depend on your configured channel rules. With `utm_medium=cpc`, it would typically match **Paid Search**.

### Using the console

You can also check the data via the JavaScript API. Open the **Console** panel and run:

```javascript
// Check if the API is available
console.log(window.__sourcetag);

// Get first click data
console.log(window.__sourcetag.getFC());

// Get last click data
console.log(window.__sourcetag.getLC());

// Check visit count
console.log(window.__sourcetag.getVisits());

// Check days to convert
console.log(window.__sourcetag.getDaysToConvert());
```

## Step 3: Check hidden fields before submitting

Navigate to a page with a form on it (keeping the same browser session so the cookie persists). In the developer tools **Elements** panel, find the `<form>` element and expand it.

You should see the hidden input fields populated with attribution data:

```html
<input type="hidden" name="st_fc_channel" value="Paid Search">
<input type="hidden" name="st_fc_detail_1" value="test">
<input type="hidden" name="st_lc_channel" value="Paid Search">
...
```

If the hidden fields aren't there:
- Make sure the script has loaded (Step 1)
- Check that the form is a standard `<form>` HTML element
- If the form loads dynamically (e.g. in a popup), it may take a moment for MutationObserver to detect it. Try opening the popup and then inspecting.

## Step 4: Submit a test form

Fill in the form with test data and submit it. Then check wherever the form data ends up:

- **Email notifications:** Check the form notification email. Attribution fields should be listed alongside the regular form fields.
- **CRM:** If your form pushes data to a CRM (HubSpot, Salesforce, etc.), check the new contact record for the SourceTag custom fields.
- **Form builder submissions:** If using a form builder (Gravity Forms, WPForms, etc.), check the submissions list in the form builder's admin.

You should see values like:

| Field | Value |
|---|---|
| st_fc_channel | Paid Search |
| st_fc_detail_1 | test |
| st_fc_detail_2 | testing-SourceTag |
| st_fc_detail_3 | (not set) |
| st_fc_detail_4 | (not set) |
| st_lc_channel | Paid Search |
| st_lc_detail_1 | test |
| st_lc_detail_2 | testing-SourceTag |
| st_fc_landing_page | / |
| st_lc_landing_page | / |

Fields that have no value (e.g. `st_fc_detail_3` when no `utm_term` was provided) show **(not set)** rather than being left blank. This is expected.

## Testing different channels

To test various channel categorisations, visit your site with different URL parameters:

| Channel to test | URL to use |
|---|---|
| Paid Search | `?utm_source=google&utm_medium=cpc&utm_campaign=test` |
| Paid Social | `?utm_source=facebook&utm_medium=cpc&utm_campaign=test` |
| Email | `?utm_source=mailchimp&utm_medium=email&utm_campaign=test` |
| Display | `?utm_source=google&utm_medium=display&utm_campaign=test` |
| Direct | Visit the bare URL with no parameters and no referrer (open a new incognito window and type the URL directly) |

For Organic Search, Organic Social and AI Referral, you'd typically need to arrive via a search engine, social network or AI assistant, as these are primarily detected by referrer domain. To test AI Referral without an assistant, use `?utm_source=chatgpt` or `?utm_medium=ai-assistant`.

## Testing first click vs last click

1. Open an incognito/private browsing window (to start with a clean cookie)
2. Visit with UTMs: `?utm_source=google&utm_medium=cpc&utm_campaign=first-visit`
3. Check the cookie. Both `fc` and `lc` should show Paid Search / google.
4. Wait a moment, then visit again with different UTMs: `?utm_source=facebook&utm_medium=cpc&utm_campaign=second-visit`
5. Check the cookie again. `fc` should still show google/first-visit. `lc` should now show facebook/second-visit.

## Troubleshooting test failures

If something isn't working, see [Troubleshooting](https://sourcetag.io/docs/troubleshooting) for common issues and fixes.
