Set up personalization

Set 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

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 personalize 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
A potential customer comes across an Acme Lease online ad based on a search they made for an electric lease car. When they click the ad, they end up on the electric lease landing page of the Acme Lease website. When they revisit the home page of the website later, they see a personalized page focused on electric lease cars instead of the above generic home page.

Acme lease electric home page

Visitors interested in leasing a used car
A different potential customer comes across an Acme Lease social ad based on a search they made for to lease a used car. When they click the ad, they end up on the used car lease landing page of the Acme Lease website. When they revisit the home page of the website later, they see a personalized page focused on leasing a 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 home page content is personalized 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 personalized page and determine how well they perform against the generic home page.

This is just one method for personalization. You could also personalize based on other characteristics such as age, gender, membership status, etc.

You could even personalize based on criteria outside of the web app, for example, when a user visits your web app from a social media link. In this case you could set up the segment to match a UTM tag on the redirect link. Check out one of our front-end app complete guides for more details.

Prerequisites

To implement personalization 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 the personalized content is defined in a Stack field. Check out the personalized page example for more details on how to define and set up a Stack field.

Home page content item

Set up personalization in your front end

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

The code above uses the Prepr customer Id. For your project, you could use your own customer Id.

Now you're ready to do the personalization setup with the below steps.

Retrieve variants using the API

Now it's time to retrieve the Home page content item including the section header variants.

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"
                        ]
                    }
                }
            ]
        }
    }
}

Take note of the following important context fields:

  • kind - This returns a value of PERSONALIZATION when personalization 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 non-personalized variant.
  • 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 and clicks.

You can do a test run of the personalization 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 users 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 personalized section headers.

Add HTML attributes to track impressions and clicks

To track visitor interactions for personalization and get accurate metrics, we need to add attributes to the section header. Usually, you'd collaborate with the marketing team to choose the component that indicates a conversion in the personalized page.

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 and clicks in Prepr, add the HTML attribute data-prepr-variant-key to the Section header and the HTML attribute data-prepr-variant-event to the CTA button.

The impression is recorded when an element, for example, the Section header, scrolls into view. While the click is recorded when an element, like the CTA button is clicked.

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

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 have integrated personalization into 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 personalization 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 personalized variants perform and make content updates, if necessary.

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

Check out the personalization for marketers doc to get a full picture on the steps needed to personalize a website.

Other use cases

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

Segments from external CRM/CDP systems

It is possible to personalize Prepr 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 personalization 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 personalized content using the API as shown in Step 1 with one difference — you must pass the Prepr-Segments header instead of 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 personalization 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