Introduction
Single-Page Application websites (SPAs) have become popular because of their ability to provide a more fluent user experience to visitors. It was made technically possible with the adoption of HTML 5, available out-of-the-box in Internet Explorer 10 and newer web browsers, and outstanding JavaScript frameworks (such as Angular, React, Ember, etc.)
Unlike traditional websites, SPA websites load content and resources dynamically. When a user interacts with the page, communication with the backend takes place behind the scenes without a new page generation and load cycle.
Prerequisites
Before you use the API, you need to:
- Have SPA campaigns enabled for your website
- Update your CD API version to 1.17 or newer
Challenge: Oracle Maxymiser and testing single-page websites
Oracle Maxymiser is implemented on test pages by loading an HTML JavaScript tag in the <head> section of the page. The browser calls our JavaScript library during the page load event, so campaign content is delivered and applied automatically even before the actual page content is displayed.
Since content on an SPA framework is primarily loaded without new page loads we cannot rely only on the initial page load from the server to run our test campaigns.
What's in the API?
With Campaign Design API version 1.17 we introduce SPA module to help marketers and developers design and build test campaigns on single-page websites. It uses the HTML5 pushState event ad DOM MutationObserver to allow applying changes on SPA websites based on custom rules, such as location change, specific node appearance, etc.
The module has been tested and used on Angular, React and other SPAs on the following browsers:
- Internet Explorer 11
- Safari latest
- Chrome latest
- Firefox latest
- Edge latest
For the full list of SPA methods in the API, see SPA reference page.
Developing your SPA campaign
This article guides you through how to deploy your first SPA campaign in Maxymiser Campaign Designer using the API.
The difference between a standard and single-page app campaign is in when the content is delivered to the visitor's browser. For SPA campaigns it is automatically mapped to any website URL, so that the content is ready immediately if target node appears, URL gets requested or any other custom condition is fulfilled. As a consequence of early content delivery, we need to send a "content seen" flag to Maxymiser as soon as the campaign is shown:
Standard | Single-page app | |
Content Generator (server-side) |
|
|
Content Rendering (client-side) |
|
|
Step 1 - Define the objective
Start by defining the objective for the campaign – the part of your website that you want to test, and how you will measure the effectiveness of the test.
Just for the sake of example, let's test a CTA:
Default | Alternative |
Step 2 - Build campaign
The next step is to create a campaign, set up URL masks, build variants' and actions' code in the Campaign Designer.
Start from a new "Campaign Designer" campaign on Campaigns Dashboard and enable "SPA Support" check-box in Campaign Settings:
Even when you specify the Campaign URLs, visitor specific experience will arrive as soon as a page would start loading, but take effect only when we specify it to. This configuration is defined in the campaign code.
Step 3 - Code experiences
To configure how campaign content is applied to a page, we use the spa module in the campaign script and variant code.
Rendering script code
The following code sets the conditions to apply changes:
When the required conditions are fulfilled successful rendering should be recorded with campaign.sendContentSeen() method call. Make sure this method is executed only once per page view as shown in the example above.
Variant code
The following code defines the modifications within a variant:
As soon as you select an action for your campaign, it starts appearing on Sandbox:
Tracking actions
You can use the spa.actions.trackClicks() to apply reversible (automatically deactivated when one of the conditions is not met) action click tracking. actions.set() and actions.send() are also applicable, but may need a wrapper to avoid duplicated tracking.
Step 4 - QA and publish
The final step of campaign development process is to confirm that campaign content and action tracking works across different browsers and put the campaign live: