# Implementation on SPA-enabled sites

### Triggering Experiences for SPA Sites

The triggering of experiences depends on the browser generating a "pageload," as most experiences are rendered when an appropriate page is loaded. However, SPA (Single Page Application) sites do not generate traditional pageloads. As a result, Gravity Field cannot launch a campaign without receiving information about pageviews.

To run a campaign on an SPA page, it is necessary to notify Gravity Field through an API call whenever the content on the SPA page changes. This includes not only complete page reloads, but also events triggered by changes to specific portions of the page, such as expanding a collapsed section, or opening a modal.&#x20;

### Sending Pageview Using API

#### Front-end API Call Forma&#x74;**:**

<pre class="language-javascript"><code class="lang-javascript">GF.API("spa", {
    context: {
        type: "PRODUCT",
<strong>        data: ["product-sku"]
</strong>    },
    url: "https://store.example.com/buy/product-sku.html",
    countAsPageview: true
});
</code></pre>

#### Parameters

<table><thead><tr><th>Property</th><th width="408.3333333333333">Description</th><th>Type</th></tr></thead><tbody><tr><td><strong>context</strong></td><td>Pass the context of the current page according to the integration documentation: <a data-mention href="/pages/hxXjxi65haZFrP2mauwK">/pages/hxXjxi65haZFrP2mauwK</a></td><td>object</td></tr><tr><td><strong>url</strong></td><td>Provide the current URL (it can be either the actual URL if the application changes the URL, or a virtual URL if the page URL remains constant). The URL is crucial to target campaigns to specific screens. If virtual URLs are used, their names must be clear to the business users of the platform.</td><td>string</td></tr><tr><td><strong>countAsPageView</strong></td><td>This parameter is used for analytics. Set it to <code>true</code> every time the entire content of the screen changes (a new page from the user's/analytics perspective), and set it to <code>false</code> when only a portion of the page changes.</td><td>boolean</td></tr></tbody></table>

This approach enables Gravity Field to track changes and trigger campaigns effectively on SPA pages.


---

# 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://developer.gravityfield.ai/lang/en/implementation/client-side-integration/spa.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.
