---
title: Page Retracks
slug: js-api/ajax-page-retracks
description: How to implement AJAX page retracks with Monetate JavaScript API
image:  https://archbee-image-uploads.s3.amazonaws.com/ceIfEvQHzQk1IVxoRWUh7/K9eTL4jKm7UQINb6zNziJ-20250912-181225.png
docTags: 
createdAt: 2024-04-26T18:30:12.626Z
---

Monetate tracks and evaluates DOM content included only in the initial page load content by default. After this initial track, if any content is served to the page through AJAX or if the page changes state asynchronously to display new data, then you must perform a retrack to make the platform aware of the new data present.

:::hint{type="info"}
A retrack is not a separate function. It's a new set of method calls to send a new track to the Monetate platform.
:::

Every retrack must include the following:

- Populating the [monetateQ](docId\:Jt7O1LQ8aUTjhFOLknLnV) object
- New content (if applicable) by using appropriate method calls based on the new context of the page
- Send the [trackData](docId\:gcm0H169GurCQMv6sBota) request

:::hint{type="warning"}
When you perform a retrack, you must always resubmit all the data in the `monetateQ` object (for example, the page type), even if that data hasn't changed.
:::

## Retrack Best Practices

Consider the following best practices when you use retracks on a page:

- Don't tie retracks to events that would exceed the rate limit of 27 per minute.
- Consider defining a page category of retrack with [addCategories](docId\:L1mhr-G5A0rK8Zc3l-_ur) so you can exclude actions from running on retracks.

## Retrack Examples

Here are some instances when a retrack may be necessary. Included with each example is the initial track and then the retrack.

### Items Added to Cart

If a customer adds an item to the cart from an index, search, or product page and is not sent to the cart page, then you can send a new track that includes the cart information.

In the first code sample, a customer adds an item from the product page, and an Add to Cart modal appears.

:::CodeblockTabs
Initial Track Example

```javascript
// Initial Track Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "setPageType",
  "product"
]);
window.monetateQ.push([
  "addProductDetails", ["a123"]
]);
window.monetateQ.push([
  "trackData"
]);
```
:::

Now that an item is in the cart, you must alert Monetate by sending a new track with the page context and the cart contents.

:::CodeblockTabs
Retrack Example

```javascript
// Retrack Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "setPageType",
  "product"
]);
window.monetateQ.push([
  "addProductDetails", ["a123"]
]);
window.monetateQ.push([
  "addCartRows", [{
    "productId": "a123",
    "quantity": "1",
    "unitPrice": "99.99",
    "currency": "USD"
  }]
]);
window.monetateQ.push([
  "trackData"
]);
```
:::

### Filter Used on Index or Search Page

A filter is triggered on the product index page but doesn't refresh the page. Therefore, you must add a retrack to the page template after the filter code to push the updated state of the page to Monetate and get instructions for modifications to the page based on this new data.

:::CodeblockTabs
Initial Track Example

```javascript
// Initial Track Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "setPageType",
  "index"
]);
window.monetateQ.push([
  "addProducts", ["a123", "b456", "c789"]
]);
window.monetateQ.push([
  "trackData"
]);
```
:::

:::CodeblockTabs
Retrack Example

```javascript
// Retrack Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "setPageType",
  "index"
]);
window.monetateQ.push([
  "addProducts", ["d123", "e456", "f789"]
]);
window.monetateQ.push([
  "trackData"
]);
```
:::

### Quick View Modal on Index or Search Page

A customer opens a quick view modal, which displays a product's details, on the product index page. Therefore, you must add a retrack to the page template to fire after the quick view modal appears.

:::CodeblockTabs
Initial Track Example

```javascript
// Initial Track Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "setPageType",
  "index"
]);
window.monetateQ.push([
  "addProducts", ["a123", "b456", "c789"]
]);
window.monetateQ.push([
  "trackData"
]);

```
:::

To register the quick view modal as a product view, send the addProductDetails call, as shown in the following code sample.

:::CodeblockTabs
Retrack Example

```javascript
 // Retrack Example
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "setPageType",
  "quickview"
]);
window.monetateQ.push([
  "addProductDetails", ["a123"]
]);
window.monetateQ.push([
  "trackData"
]);
```
:::

## Testing Retracks

Once you have triggered a retrack, you can test it to ensure it works. First, put your Web application in the state in which you expect it to display the action(s) that you built, and then paste the lines of code into the JavaScript console. The actions should download in the retrack and run successfully.

You can also use the [Monetate Inspector](https://docs.monetate.com/docs/install-the-monetate-inspector-browser-plug-in) browser plug-in to see additional tracks.

:::hint{type="warning"}
Recent updates to Safari Intelligent Tracking Prevention (ITP) block third-party cookies on your site. This update means that Preview Mode and the Monetate Inspector browser plug-in may not work in Safari.&#x20;

Monetate has developed an alternative approach to delivering Preview Mode to the site. To have this option enabled for your account, submit a support ticket using the Monetate Technical Support portal (support.monetate.com).

No workaround exists at this time for the Inspector tool. Instead, use a different browser such as Chrome if you need to use Monetate Inspector.
:::

Launch Monetate Inspector while you're on a page that you know has an AJAX operation, such as a change in search terms. Next, perform the AJAX operation while on the **Track** tab in the plug-in tool.

![Callout of the Track tab in Monetate Inspector](https://dyzz9obi78pm5.cloudfront.net/app/image/id/64f75491bbe7a003d7101762/n/monetate-inspector-track-tab-3.png)

After you initiate the AJAX operation, the track count should increase by one. In this screenshot the track count has changed from **Track 3**, shown in the previous screenshot, to **Track 4**.

![Callout of the Track selector in the Monetate Inspector, which is set to Track 4](https://dyzz9obi78pm5.cloudfront.net/app/image/id/64f75491438feb58203fbdf4/n/monetate-inspector-track-tab-4.png)

Once you see the additional track added to the track selector, you know that the retrack works and then can close Monetate Inspector.

## Retracks and the Average Page View Metric

Each [trackData](docId\:gcm0H169GurCQMv6sBota) call made to Monetate through the API or a Monetate-built implementation registers as a page view. Therefore, if more than one `trackData` call happens on a single page, page views may be inflated in the Monetate platform's internal analytics.

You can use an optional `{'nonPageView': true}` parameter for the `trackData` call to prevent it from counting as a page view.

:::CodeblockTabs
Example Track with nonPageView Parameter

```javascript
// Example Track
window.monetateQ.push([
  "trackData",
  {
    "nonPageView": true
  }
]);
```
:::

