---
title: "Custom Ads With AJAX"
description: "Thesis Ghost theme loads pages with AJAX, so AdSense ad units must be pushed again on the pvs.navigation.content-rendered event after each transition."
url: "https://www.priority.vision/docs/thesis/custom-ads-with-ajax"
scope: theme
appliesTo: [Thesis]
lastUpdated: 2026-10-01
---

# Display Ads with AJAX

When implementing ads in an AJAX-powered Thesis theme, you need to properly handle ad initialization after page transitions. Here's how to set up Google AdSense, though similar principles apply to other ad networks.

## Add AdSense Script

    [Code Injection](/docs/guides/custom-code-injection/) is required to add custom JS.

First, add the Google AdSense script to your site's head section:

```html
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXX"></script>
```

## Place Ad Units

    [Editing Theme Code](/docs/guides/advanced-editing-theme-code/) is required to add these changes.

Next, place the ad unit code where you want the advertisement to appear. This will require customizing your theme templates:

```html
<ins class="adsbygoogle"
  style="display:block"
  data-ad-client="ca-pub-XXXXXXX"
  data-ad-slot="XXXXXXXXXX"
  data-ad-format="auto"></ins> 
```

## Initialize Ads

    [Code Injection](/docs/guides/custom-code-injection/) is required to add custom JS.

Finally, add this JavaScript code to handle ad initialization after AJAX navigation:

```html
<script>
  window.ivent.on(document, 'ready pvs.navigation.content-rendered', () => {
    if ( document.querySelector('ins:empty') ) {
      (window.adsbygoogle = window.adsbygoogle || []).push({});
    }
  });
</script>
```

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