> ## Documentation Index
> Fetch the complete documentation index at: https://docs.navattic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Install Navattic JS

> Install and configure the Navattic JS tracking script.

<Icon icon="square-code" /> **Navattic JS** is a script that can be added to your website or application to identify and track visitors to your demos.

It's a powerful tool to track visitors since it integrates with the existing identity layer of your application or website. There are two useful ways to use Navattic JS:

<CardGroup>
  <Card title="Identify Visitors" icon="user-round-check" href="#identify-visitors-with-navattic-js">
    Unlock significantly more identified visitors by calling `navattic.identify()` whenever you have the visitor's email.
  </Card>

  <Card title="Subscribe to events" icon="code" href="/tracking/navattic-js/subscribe-to-events">
    Integrate with any tracking scripts already installed on your website by calling `navattic.onEvent()`.
  </Card>
</CardGroup>

## Navattic JS Setup

Follow these steps to add the Navattic JS tracking scripts to your websites and applications.

<Steps>
  <Step title="Navigate to setup steps">
    Navigate to the [Navattic JS settings](https://app.navattic.com/w/settings/js) and then follow steps to add the Navattic JS tracking scripts to your website and app.

    <img src="https://mintcdn.com/navattic-app/yCXI67hPOjoXNzVe/images/navattic-js-setup.png?fit=max&auto=format&n=yCXI67hPOjoXNzVe&q=85&s=89520aef8b1d28d521a6266ff0f83c03" alt="Navattic JS Setup" width="1736" height="416" data-path="images/navattic-js-setup.png" />
  </Step>

  <Step title="Decide which websites and apps to track">
    Navattic JS can be added to any website or application that you want to track.

    To unlock the greatest number of identified visitors, we recommend adding Navattic JS to your app (**app.company.com**), as well as any websites hosting your demos. <img src="https://mintcdn.com/navattic-app/yCXI67hPOjoXNzVe/images/navattic-js-website-config.png?fit=max&auto=format&n=yCXI67hPOjoXNzVe&q=85&s=2701a1199c9434742b87751ad3ce43a7" alt="" width="1736" height="768" data-path="images/navattic-js-website-config.png" />
  </Step>

  <Step title="Copy and paste the tracking script">
    Under the `Implementation checklist`, copy the script and follow instructions to add it to the `<head>` of your website or application.

    [Calling Navattic JS Identify](#calling-navattic-js-identify) (Recommended).
  </Step>

  <Step title="Adjust configuration (optional)">
    Customize the behavior of Navattic JS by adjusting the configuration settings.

    <Tabs>
      <Tab title="Auto form tracking">
        Automatically track visitor information from external forms embedded outside of your Navattic demo.

        For example, if a Visitor completes a HubSpot form elsewhere on your marketing website, their email address will now be surfaced in the Navattic Visitors tab and available to use in Navattic Playbooks (i.e., Integrations).

        <Info>
          See [Capturing forms in iframes](#capturing-forms-in-iframes) for details on browser and Pardot restrictions.
        </Info>
      </Tab>

      <Tab title="Cross-domain tracking">
        Track visitors across sub-domains. For example, this will allow you to track the same visitor on your marketing website (**company.com**), docs (**docs.company.com**), and blog (**blog.company.com**).
      </Tab>

      <Tab title="CRM tracking scripts">
        Navattic JS can automatically match demo visitors to HubSpot or Marketo contacts using existing cookies. Their demo activity will sync to your CRM, and if email capture is enabled (via automatic form submissions or JavaScript), the visitor’s email will also appear in the Navattic Visitors tab.
      </Tab>

      <Tab title="Query parameter tracking">
        Automatically include page query parameters from the parent page as Navattic visitor attributes. For example, if a demo visitor views an embedded demo on `navattic.com/pricing?utm_medium=internal\&client_id=chromestore`, the parameters `utm_medium` and `client_id` will automatically turn into Visitor properties.
      </Tab>
    </Tabs>
  </Step>
</Steps>

## Identify visitors with Navattic JS

Once you've [installed Navattic JS](#navattic-js-setup), you can call the `identify` method to anytime you have the visitor's email address available.

This identification method will be prioritized over other [automatic tracking configuration methods](#auto-form-tracking).

```javascript theme={null}
// Add to a place where user.email is available
navattic.identify({ email: user.email })
```

### FAQ

<Accordion title="Capturing Forms in iFrames">
  Due to browser security restrictions, [Navattic JS](/tracking/navattic-js) can’t automatically capture form submissions from iframes. For those cases, as a workaround, it is possible to add code to the form that will send the submission to the parent page so that Navattic JS can identify the visitor and associate them with the demos elsewhere on your site.

  For Pardot and other form providers that allow you to include a script tag within the form, below is an example of a script that can be added to your form that will pass the form submission to Navattic JS.

  Note: you may need to update the `KEYS_TO_SEND` and the element ID values of your script with values that are specific to your form configuration.

  ```html theme={null}
  <script>
    function sendFormToNavattic(event) {
      event.preventDefault();

      const form = event.target;
      const formData = new FormData(form);
      const KEYS_TO_SEND = ['name', 'email', 'phone']; // This can be customized

      const data = {};

      for (const [key, value] of formData.entries()) {
        if (KEYS_TO_SEND.includes(key)) {
          data[key] = value;
        }
      }

      if (Object.keys(fields).length > 0) {
        window.parent.postMessage({
          kind: 'navattic:iframe-form-submission',
          fields,
        });
      }
    }
    const formElement = document.getElementById('iframe-form'); // use the actual form selector
    formElement?.addEventListener('submit', sendFormToNavattic);
  </script>
  ```
</Accordion>
