# JavaScript Testing

{% hint style="info" %}
📚 Web Form Attribution Series - Part 3 of 3

**Part 1:** [Web Form Attribution Tracking](/how-to-guides/web-form-attribution.md) - Implementation guide

**Part 2:** [JavaScript Overview ](/how-to-guides/javascript-overview.md)- Understanding the JavaScript

**Part 3:** JavaScript Testing Guide **(you are here)**
{% endhint %}

**This Document Will Cover:**

* [Prerequisites](#prerequisites)
* [Initial Setup and Cache Clearing](#initial-setup-and-cache-clearing)
* [Testing Multiple Domains/Subdomains](#testing-multiple-domains-subdomains)
* [Core Attribution Testing](#core-attribution-testing)
* [Salesforce Verification](#salesforce-verification)
* [Advanced Debugging](#advanced-debugging)
* [Troubleshooting Common Issues](#troubleshooting-common-issues)
* [Expected Processing Times](#expected-processing-times)
* [Testing Checklist](#testing-checklist)

{% hint style="info" %}
**Quick Reference for Technical Users**

1. Clear everything: `imt.clearCache();` + clear local storage
2. Set UTMs: `?utm_medium=medium1...` then `?utm_medium=medium2...`
3. Inspect form: Search for "medium1" (First-Click) and "medium2" (Last-Click)
4. Submit with unique email: `YYYYMMDD_HHMM@domain.com`
5. Verify in Salesforce: Lead → Engagement record

**Debug in browser console:** `imt.enableDebug();` (enable) | `imt.clearCache();` (clear cache)

*For detailed step-by-step instructions, continue below.*
{% endhint %}

## Prerequisites

* Integrous JavaScript must be installed on all pages being tested
* Hidden form fields must be present on forms (see [Web Form Attribution Tracking guide](/how-to-guides/web-form-attribution.md))
* Access to Salesforce to verify results
* Marketing Automation Platform sync enabled
* Basic familiarity with browser developer tools

## Initial Setup and Cache Clearing

{% stepper %}
{% step %}

### Complete Browser Reset

1. Close all tabs for all domains and sub-domains related to the customer anywhere on your computer
2. Open each domain and sub-domain you plan on testing in separate tabs
   {% endstep %}

{% step %}

### Clear Cache and Storage for Each Tab

Complete the following steps in **each tab** you opened:

1. Right-click anywhere on the page and click 'Inspect Element' to open developer tools
2. Right-click the 'Refresh' icon in the browser next to the URL bar and select "Empty Cache and Hard Reload"
3. Go to the **Console** tab in the developer tools
4. Type: `imt.clearCache();`
5. Hit **ENTER**
6. Go to the **Application** tab in the developer tools
7. Navigate to **Local Storage** in the left sidebar
8. Right-click and select 'Clear' for each entry in the local storage
   {% endstep %}
   {% endstepper %}

## Testing Multiple Domains/Subdomains

If testing cross-domain tracking:

* Test each domain/subdomain separately first
* Then test navigation between them to verify attribution persists
* For subdomains (e.g., [blog.company.com](http://blog.company.com/), [www.company.com](http://www.company.com/)), the JavaScript should automatically share data

{% hint style="info" %}
**Note:** For cross-domain tracking to work, Integrous must configure each domain for you in the JavaScript settings.
{% endhint %}

## Core Attribution Testing

{% stepper %}
{% step %}

### Primary UTM Test

1. **Set First Attribution:**
   1. Copy/paste the following to the end of the URL you'd like to test:
      1. `?utm_medium=medium1&utm_source=source1&utm_campaign=campaign1&utm_content=content1&utm_term=term1`
   2. Hit **ENTER**
2. **Set Second Attribution:**
   1. Replace the query string with this new query string:
      1. `?utm_medium=medium2&utm_source=source2&utm_campaign=campaign2&utm_content=content2&utm_term=term2`
   2. Hit **ENTER**
3. You've now stored two sets of UTMs in your browser's local storage
   {% endstep %}

{% step %}

### Form Field Verification

1. Navigate to the form you'd like to test
2. Right-click anywhere on the page with the form and click "Inspect Element" to open developer tools
3. Click on the **Elements** tab in the developer tools if it's not already selected

#### Visual Verification in Developer Tools

1. **Command+F** on Mac or **Ctrl+F** on Windows and search for "medium1"
   1. Confirm it corresponds to the First-Click (FC) Medium hidden field
   2. Look for field names like: `IA_-_PROCESSING_FC_UTM_MED__c`
2. **Command+F** on Mac or **Ctrl+F** on Windows and search for "medium2"
   1. Confirm it corresponds to the Last-Click (LC) Medium hidden field
   2. Look for field names like: `IA_-_PROCESSING_LC_UTM_MED__c`
3. Verify these fields contain your test UTM values
   {% endstep %}

{% step %}

### Form Submission and Tracking

1. Submit the form, using a new unique email address
2. **Format:** `YYYYMMDD_HHMM[AM/PM]@[your domain].com`
3. **Example:** `20240911_1228pm@integrousanalytics.com`
   {% endstep %}
   {% endstepper %}

## Salesforce Verification

{% stepper %}
{% step %}

### Salesforce Data Validation

1. **Wait for Processing:** Give time for the Marketing Automation Platform to process that information and sync to Salesforce
2. **Find the Lead:** Search for the lead with that email address in Salesforce
3. **Check Engagement Record:** Click on the Engagement record associated with that lead
4. **Confirm All Fields:** Verify all the fields set by the JavaScript captured the info you expect to find:
   1. Five 'First-Click' (FC) UTMs and External ID
   2. Five 'Last-Click' (LC) UTMs and External ID
   3. Entry Page
   4. Conversion Page
      {% endstep %}
      {% endstepper %}

## Additional Test Scenario - Cross-Domain Navigation

* Start on one domain with UTMs
* Navigate to subdomain
* Submit form on subdomain
* Verify attribution persists across domains

## Advanced Debugging

### Enable Debug Mode

**Enable Debug Through the Developer Console:**

* Open the Developer Console in your browser (usually accessible via **F12** or **Ctrl + Shift + I**)
* Run the function: Enter `imt.enableDebug();` in the console and press **ENTER**
* Refresh the page to apply the changes
* Repeat this step for each subdomain if needed
* To disable debug mode, clear the local storage value `debug-mode`

### Complete Cache Clearing

To fully clear the cache for a subdomain, run the following command in the browser's developer console:

`imt.clearCache();`

## Troubleshooting Common Issues

### JavaScript Not Loading

* Check browser console for errors
* Verify GTM is firing on the page
* Confirm JavaScript tag is set to fire on "All Pages"

### Hidden Fields Not Populating

* Verify field names match JavaScript configuration
* Check if form is in an iframe (requires special setup)
* Confirm fields are not pre-populated with values
* Ensure form fields are actually hidden (not just invisible)

### Attribution Not Reaching Salesforce

* Check Marketing Automation Platform field mapping
* Verify "Processing" fields are being populated
* Check Salesforce user permissions
* Confirm MAP sync is enabled and running
* Ensure field mapping between the MAP and Salesforce is configured correctly

### Cross-Domain Issues

* Verify all domains are configured in JavaScript settings
* Check that JavaScript is installed on all domains/subdomains

## Expected Processing Times

* **JavaScript populates fields:** Immediate
* **MAP sync to Salesforce:** 5-15 minutes (varies by platform)
* **Engagement record creation:** Immediate upon MAP sync completion

## Testing Checklist

* [ ] JavaScript loads without console errors
* [ ] Hidden fields populate with correct UTM values
* [ ] Form submission successful
* [ ] Lead created in Salesforce with unique email
* [ ] Engagement record created and linked to Lead
* [ ] All attribution fields populated correctly
* [ ] First-click attribution shows "medium1, source1, campaign1, content1, term1"
* [ ] Last-click attribution shows "medium2, source2, campaign2, content2, term2"
* [ ] Entry Page and Conversion Page URLs captured
* [ ] Cross-domain tracking works (if applicable)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.integrousanalytics.com/how-to-guides/javascript-testing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
