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

# Track Outbound Links

> Learn how to track outbound link clicks in Oppla

# Track Outbound Links in Oppla

When a user clicks on a link to an external site, this event is normally not captured because the user is leaving the site where Oppla runs. However, you can use events to track this behavior.

### Using Data Attributes

To track outbound links, add data attributes to the anchor tag containing the external link. When the tag is clicked, the event will be triggered. For example:

```html theme={null}
<a href="https://www.external-website.com"
  data-oppla-event="outbound-link-click"
  data-oppla-event-url="https://www.external-website.com"
>
  External link
</a>
```

This sends an event named **outbound-link-click** with the value of `url` set to the external URL.

### Automating Event Attributes

If you don't want to manually update all your anchor tags, use the following script to automatically add the event attributes to all outbound tags. Place this script at the bottom of your HTML body:

```html theme={null}
<script type="text/javascript">
  (() => {
    const name = 'outbound-link-click';
    document.querySelectorAll('a').forEach(a => {
      if (a.host !== window.location.host && !a.getAttribute('data-oppla-event')) {
        a.setAttribute('data-oppla-event', name);
        a.setAttribute('data-oppla-event-url', a.href);
      }
    });
  })();
</script>
```

### Verifying Outbound Link Tracking

After implementing the above, verify the tracking by clicking on an outbound link and checking the **Events** section in your Oppla dashboard.

💡 For further guidance, visit our Help Center or reach out to support.
