Setting up personalization

Setting up personalization

Estimated duration: 15-30 minutes

This guide demonstrates how to set up personalization and the related metrics in your web application using the Prepr GraphQL API.

Introduction

Prepr lets you create personalized experiences with Adaptive content. With Adaptive content, content editors can make different versions of content for various visitor segments. You can then show the right content to each visitor based on their segment giving them a personalized experience. By doing the one-time setup detailed below, Prepr can track and measure the visitor interactions for each adaptive content element.

Use case

Let's look at an everyday use case. The marketing team wants to improve user experience and the clickthrough rate of the home page header. They've decided to group their customers into two main segments: Customers who lease electric cars and customers who lease used cars. Based on these segments they add adaptive content to the home page to target these customers separately.

General website visitors
When customers navigate to the Acme Lease home page, they see a generic page like in the image below.

Acme lease home page

Visitors interested in leasing an electric car
When a potential customer searches for an electric lease car and clicks on an Acme Lease ad, they are directed to the electric lease landing page on the Acme Lease website. If they visit the home page again later, they'll see content focused on electric lease cars instead of the usual generic home page.

Acme lease electric home page

Visitors interested in leasing a used car
Another potential customer sees an Acme Lease social ad after searching for used car leasing options. When they click the ad, they’re taken to the used car lease landing page on the Acme Lease website. Later, when they revisit the home page, they see content focused on leasing used cars.

Acme lease occasional home page

For this use case, the front-end application has been set up to track each visitor's behavior based on their interests. When they view a particular landing page, Prepr places them in the correct segment.

The adaptive content in the home page is for two segments: Electric Car Lovers and Used Car Lovers. This allows the front end to display the correct home page for each segment.

The marketing team can then evaluate metrics in Prepr to measure conversions for each element with adaptive content and determine how well they perform against the generic home page.

Prerequisites

To implement adaptive content for the above example, you need to have the following set up in Prepr beforehand:

We will make use of the Home Page content item from the Acme Lease demo data. Take note that adaptive content is defined in a Stack field.

Home page content item

Set up personalization in your front end

Before setting up personalization in your front end, make sure the following points have been prepared:

Now you're ready to set up personalization in the following steps:

  • Step 1: Retrieve adaptive content using the API.
  • Step 2: Add HTML attributes to track impressions and conversion events.

Retrieve adaptive content using the API

Now it's time to retrieve the Home page content item including the adaptive content elements.

Copy the sample code below into your front-end application.

query{
   Page (id: "6b9aab64-4972-4049-810f-333fc89bf87c") {
    title
        stack {
            ... on SectionHeader {
                title
                image {
                    name
                }
                text
                cta_button
                _context {
                    kind
                    variant_id
                    variant_key
                    segments
                }
            }
        }
    }
}

Update the id string of the query with the Content item ID of the Home page. See the image below on where to find the Content item ID on the content item page.

content item ID

To retrieve the page content, call the API using the query above and pass a Prepr Customer ID as a header as shown below. The Prepr Customer ID is required to determine which segment a visitor belongs to and as a result which variant a visitor gets.

--header 'Prepr-Customer-Id: <YOUR-CUSTOMER-ID>' 

Follow the Connecting front-end apps guide to learn more about retrieving content items in a specific framework.

As a response to your API request, Prepr sends the variant to be displayed. Your app then needs to build its response based on this variant. If you don't specify a customer Id in the header or the customer Id is for a visitor that does not belong to either segment, then the query response looks like the example below.

{
    "data": {
        "Page": {
            "title": "Homepage",
            "stack": [
                {
                    "title": "Welcome to Acme Lease 👋🏼 Find your car",
                    "cta_button": {
                        "text": "Find a car"
                    },
                    "_context": {
                        "kind": "PERSONALIZATION",
                        "variant_id": "ALL_OTHER_USERS",
                        "variant_key": "eyJpIjoiZGJkMDY0NjctMDNiMy00N2Q1LTkxNmEtZjM2ZjRiYTkyM2FiIiwiZSI6IjNiOWE0M2NhLTJkMjctNDg1Yi1hMWI3LTgwNWE4YTcyZGQzNSIsInYiOiJBTExfT1RIRVJfVVNFUlMifQ="
                    },
                }
            ]
        }
    }
}

If the customer Id in the header matches a visitor that belongs to one of the segments, then the query response looks like the example below.

{
    "data": {
        "Page": {
            "title": "Homepage",
            "stack": [
                {
                    "title": "Green your drive ☘️ Lease top electric cars!",
                     "cta_button": {
                        "text": "Find a car"
                    },
                    "_context": {
                        "kind": "PERSONALIZATION",
                        "variant_key": "eyJpIjoiZGJkMDY0NjctMDNiMy00N2Q1LTkxNmEtZjM2ZjRiYTkyM2FiIiwiZSI6IjNiOWE0M2NhLTJkMjctNDg1Yi1hMWI3LTgwNWE4YTcyZGQzNSIsInYiOiJFTEVDVFJJQy1DQVItTE9WRVJTIn0=",
                        "variant_id": "ELECTRIC-CAR-LOVERS",
                        "segments": [
                            "8f1e1cac-c3a8-4716-b911-db37446de85f",
                            "electric-car-lovers"
                        ]
                    }
                }
            ]
        }
    }
}

Check out the Manage adaptive content settings doc on how to enable the option to retrieve all matching variants.

Take note of the following important context fields:

  • kind - This returns a value of PERSONALIZATION when adaptive content is enabled for this element in the Stack.
  • variant_id - This returns a value of the segment for the variant, for example, ELECTRIC-CAR-LOVERS. This value is ALL_OTHER_USERS for the variant not assigned to any specific segment.
  • variant_key = A unique Id for the variant. You will use this field value in the next step to indicate which components need to be tracked for impressions.

You can do a test run with the adaptive content in Prepr before launching it on your live website:

  1. Open the API Explorer as described here.
  2. Copy and paste the GraphQL query above into the Operations pane.
  3. Run the query. You'll get the section header for All other customers because you didn't send a customer Id.
  4. Under the Header section, enter Prepr-Customer-Id with a Customer ID value in one of the segments. On the Segments screen, find the Id on the right when you edit a specific customer.
  5. Re-run the query. You'll now get one of the section headers with adaptive content.

Add HTML attributes to track impressions and conversion events

To track visitor interactions with adaptive content and get accurate metrics, we need to add attributes to the section header. Usually, you'd collaborate with the marketing team to choose the element and the corresponding event that indicates a conversion in the page with adaptive content.

In our example, we have a section header with some specific text and a call-to-action button for each variant, so we want to report on the following types of visitor interactions:

  • Impressions: How many visitors viewed the section header for each variant.
  • Clicks: How many visitors clicked the CTA button for each variant.

Prepr will determine the conversion rate and other related metrics based on these events and will show you which variant performed best.

To start collecting impressions, add the HTML attribute data-prepr-variant-key to the Section header. The impression is then recorded when the Section header element scrolls into view.

Set the data-prepr-variant-key value to the Prepr variant key value returned in the query response.

To start collecting clicks, add the HTML attribute data-prepr-variant-event to the CTA button. The click is recorded when the CTA button element is clicked.

If you want to track a conversion other than a click event, e.g. a quote request, then set your data-prepr-variant-event to the custom event. For example: data-prepr-variant-event="QuoteRequest".

See an example code snippet to include the HTML attributes below:

...
<!-- section header -->
<div class="..."  data-prepr-variant-key="{{ variant_key }}">
  <!-- section header image -->
  <img src="..." class="...">
  <div class="...">
    <div class="...">
      <!-- section header text -->
      <h1 class="...">...</h1>
      <span>
        <!-- section header button -->
        <a href="/catalog?category=electric" data-prepr-variant-event>
          <button class="...">Find your car</button></a>
      </span>
    </div>
</div> 
...
 

That’s it. You've set up adaptive content in your website. Now, you can show each visitor a personalized header based on their clicking behavior.

As visitors interact with your web app, data will be collected and metrics will be visible in the adaptive content group. Go to the Home page content item to see the metrics.

Metrics example

After some time the marketing team will be able to evaluate metrics to determine how well the variants with adaptive content perform and adjust the content, if necessary.

Congratulations, you have successfully set up adaptive content on your web app.

Check out the marketers' adaptive content guide to get a full picture on the steps needed to add adaptive content to your website.

Other use cases

This guide explains just one use case for adaptive content. Below we list a few more common options.

Segments from external CRM/CDP systems

It is possible to set up adaptive content based on segments maintained in other CDP/CRM systems or segments based on UTM tags (for instance from an ad campaign). This means that customer data doesn't have to be imported into Prepr. In this case, you need to reference these external segments from within Prepr using the segment unique identifier from that system or the UTM tag.

Your adaptive content flow will look like this:

  1. Create a new segment in Prepr and set the ID value to the segment unique identifier copied from your CRM/CDP system or the UTM tag.

  2. Retrieve adaptive content using the API with one difference — you must pass the Prepr-Segments header instead of the Prepr-Customer-Id. For more information, refer to our API documentation.

  3. If the segment is based on external customer data, ensure that your front end is connected to the external CRM/CDP system for data retrieval.

Want to learn more?

Check out the following chapters:

Schedule a free consultation

Do you want to get started with adaptive content but still have questions or want a demo?

Schedule a free call (opens in a new tab) with a Prepr solution engineer.

Was this article helpful?

We’d love to learn from your feedback