On a Single Page Application (SPA), the page content changes without a reload. How does iAdvize follow your visitors as they navigate, and what do you need to do so that your targeting rules, engagement strategies and Conversation Starters display on the right page?
How iAdvize follows navigation in an SPA
Each time a navigation is detected in the application, iAdvize runs targeting again for the new page, even if the page was not reloaded:
- targeting rules and engagement strategies are evaluated again for the new page;
- Conversation Starters and widgets that no longer match the page are removed;
- the page element targeted by a Conversation Starter’s CSS selector is looked up again, for up to 12 seconds after the navigation.
(Click on the image to see it in large size)
For example, in a sign-up funnel, the form is loaded once and then displayed step by step. SPA targeting lets you engage the visitor based on the step they see, or on an error displayed in the form:
What you need to do depends on how your application handles the URL.
SPA with URL changes
The URL in the address bar changes with each screen. This is the standard behavior of frameworks such as React, Vue or Nuxt.
No action is needed. The iAdvize tag detects each URL change on its own, including without a page reload. All targeting criteria work as on a standard website: build your rules and strategies on the URLs of your screens.
iAdvize.navigate() (see the next section) once the element is displayed, to run targeting again on the page.
iAdvize.navigate(), as for an SPA without URL changes.
SPA without URL changes
The URL in the address bar never changes, whatever the navigation in the application. iAdvize cannot tell on its own that the visitor changed screens: you need to tell it.
The global JavaScript object iAdvize exposes the navigate function for this, which declares a navigation within the current page:
<script>
window.iAdvizeInterface = window.iAdvizeInterface || [];
iAdvizeInterface.push(function(iAdvize) {
iAdvize.navigate("MY_PATH");
});
</script>
- Replace “MY_PATH” with the name of the screen the visitor lands on, for example
/etape-2. Your targeting rules use this name as they would use a URL. - The function takes a single argument, of type String.
- Called with an empty value (
""), it uses the current URL of the page.
Example: trigger targeting when a button is clicked
You want to offer a conversation to the visitor when they click the Next button of a form. On click on this button, add to your website code:
<script>
window.iAdvizeInterface = window.iAdvizeInterface || [];
iAdvizeInterface.push(function(iAdvize) {
iAdvize.navigate("/etape-2");
});
</script>
The targeting rule that matches this screen change:
Check the navigation taken into account
On a page of your website, open the browser console (right-click, Inspect, Console tab) and type iAdvize.vStats.actualScreen. The command returns the URL or screen name used by targeting:
iAdvize.vStats only exists when the tag is in FULL mode, that is, after a targeting rule has been triggered on the page. See iAdvize doesn’t appear on my website: what to check