A Developer’s Guide to Dynamic Content Personalization

Learn about audience targeting on WordPress VIP.

(null)

As your site traffic and content library grow, so does the need to surface relevant content for your audience. Personalization allows you to serve dynamic content to your site’s visitors, increasing engagement and, ultimately, conversions.

At the same time, site performance is an important component of the user experience and can influence search engine rankings. The highest levels of performance are achieved by caching content for a set period and serving it from the data center nearest the end user through a content delivery network (CDN). This ensures the minimum latency possible for site visitors, providing a better user experience while enabling sites to scale quickly to handle large amounts of traffic.

At first glance, site performance and dynamic content seem like competing priorities with little overlap. But both can co-exist comfortably and complement each other to drive highly performant, personalized content.

Types of personalization

Content personalization comes in many flavors, but it always comes down to providing your audience with a more customized and engaging experience. Dynamic content includes:

  • Content that is specific to locales
  • Curated content based on what a reader has viewed or liked in the past
  • Content targeted to specific demographics
  • Content based on predictive analytics or recommendation engines and APIs

For sites with user-generated content, dynamic content can also include users following certain people or topics for a more relevant feed, or sharing their own content to be consumed.

How to personalize content on WordPress VIP

The WordPress VIP platform offers powerful APIs for segmenting content while maintaining cacheability and maximum performance. By default, WordPress VIP serves cached content to unauthenticated visitors to ensure the fastest user experience. 

For users logged into your WordPress site, each response is uncached and already tailored to them with no extra steps required. But what about the middle-ground—unauthenticated users you wish to serve dynamic content to?

The Cache Personalization API provides a programmatic way to control WordPress VIP’s edge cache and serve multiple unique copies of the same resource, each tailored to specific segments of users. This is achieved by grouping similar users into segments and caching the responses for each unique segment separately.

A segment represents a unique cache bucket within a group in which all users of the same segment can receive the same cached response. To begin segmenting users into separate cache buckets, first define the groups to support. A group is a related set of segments.

Let’s use the example of A/B testing three different versions of article headlines to gauge their effectiveness with readers. To do this, create an “Article Headlines” group that consists of three segments: a, b, and c.

First, load the Cache Personalization API:

Copy Code
​​// Load the VIP Vary_Cache class
require_once( WPMU_PLUGIN_DIR . '/cache/class-vary-cache.php' );

use Automattic\VIP\Cache\Vary_Cache;

Then we can register our “Article Headlines” group:

Copy Code
Vary_Cache::register_group( 'article_headlines' );

By registering the group, the Cache Personalization API knows to vary the cache based on a user’s segment in this group. First, register each group with the Vary_Cache class. 

Then, assign users to specific segments within the group by using this function:

Copy Code
Vary_Cache::set_group_for_user( $group, $segment ); 

How you define a user’s segment is up to you. For example, users can opt-in to segments, be assigned based on characteristics of the request (like their browser), or be assigned at random. When you’ve decided which segment a user belongs to, simply assign them:

Copy Code
Vary_Cache::set_group_for_user( 'article_headlines', 'b' );

The above code instructs the Cache Personalization API to persistently place the current user into the b segment for article headlines. Subsequent requests from this user will return cached content for the b segment. The user’s segments are saved in a cookie.

Note: The default cookie lifetime for cache segments is one month. Adjust this by calling:

Copy Code
Vary_Cache::set_cookie_expiry( $ttl_in_seconds );

The minimum cookie TTL is one hour.

Now that the user is segmented, the appropriate content can be served to them. Simply check which segment they belong to and alter the response accordingly:

Copy Code

if( Vary_Cache::is_user_in_group_segment( 'article_headlines', 'a' ) {
    echo esc_html( $article_headline_a );
} else if ( Vary_Cache::is_user_in_group_segment( 'article_headlines', 'b' ) {
    echo esc_html( $article_headline_b );
} else {
    // Default, user is not in another segment
    echo esc_html( $article_headline_c );
}

Multiple groups and segments can be used for the same request/user, and there are no imposed limits on the number of groups and segments. However, note that each combination of group + segment represents a unique cache bucket, which can reduce your site’s overall cache hit rate.

The fewer unique groups + segments your site has, the higher your edge cache hit rate, and, by extension, the lower your overall response times. Higher cache hit rates and lower response times are ideal for site performance.

Encryption

As noted, a user’s segments are stored in a cookie on the user’s computer. This cookie is not encrypted or signed, which is suitable for most uses of the Cache Personalization API. However, if the segmentation data is sensitive or you need to limit tampering (such as preventing spoofed cookies from bypassing paywalled content), the segmentation cookie can be encrypted and signed. 

To encrypt your segmentation cookies, reach out to the WordPress VIP support team.

Geo-targeting

Geo-targeting is commonly used to vary the cache. Rather than implement this yourself with the lower-level Cache Personalization API, a WordPress VIP plugin—VIP Geo Uniques—can do the heavy lifting for you. This plugin makes it easy to serve different content based on the visitor’s geographic location—or even prevent access to your content from specific locations—without manually varying the cache or assigning users to groups and segments.

To begin, install the plugin into the plugins or client-mu-plugins directory in your site’s repository and load it:

Copy Code
wpcom_vip_load_plugin( 'vip-go-geo-uniques' );

Geo Uniques matches a visitor’s IP address to their country of origin and automatically varies the cache by country. The WordPress VIP platform supplies country information to the request via $_SERVER['GEOIP_COUNTRY_CODE'], then the plugin uses this information to vary the cache for the countries you define.

To ensure maximum cacheability, Geo Uniques will only vary the cache for the set of countries specified in code. This ensures high cache hit rates while allowing customized responses for countries that require different content. 

For this task, define the default country. This cache bucket will be used when the user’s country is not one of the defined countries with differing content:

Copy Code
VIP_Go_Geo_Uniques::set_default_location( 'US' );

Now define the list of countries for which to return different responses using their ISO 3166 country code:

Copy Code
VIP_Go_Geo_Uniques::add_location( 'GB' ); // United Kingdom
VIP_Go_Geo_Uniques::add_location( 'FR' ); // France
VIP_Go_Geo_Uniques::add_location( 'DE' ); // Germany

With the supported countries defined, check the user’s country and alter the response accordingly:

Copy Code
if ( function_exists( 'vip_geo_get_country_code' ) && 'GB' === vip_geo_get_country_code() ) {
    echo 'Please select your favourite colour:';
} else {
    echo 'Please select your favorite color:';
}

For more details, refer to WordPress VIP Geo Uniques plugin documentation.

Parse.ly personalization tools

Parse.ly, part of WordPress VIP, offers multiple tools to facilitate personalization efforts, including a Content API and audience segmentation. 

Content API

Using the Parse.ly plugin for WordPress, access the Content API to quickly and easily integrate content recommendations across all of your channels. Part of the Content API includes a Recommendations Block, available in WordPress, that suggests related content to your user to boost engagement and increase recirculation.

Example of the Recommendations Block in action, highlighting "Related Content" in the WordPress admin

Audience segmentation

Audience segmentation is used to understand the behavior of the various target user groups in your audience, serving as a valuable way to gather key insights to inform your personalization strategy. Parse.ly offers ready-to-use segmentation solutions, or you can build your own.

Whether you want to target users by geographical location (similar to geo-targeting mentioned above), subscriber base, or membership level—Parse.ly allows you to segment and analyze your audience engagement data to inform a personalization strategy for each cohort

By using Parse.ly’s geo-segments, Bloomberg was able to gauge local audience interests, optimize their content for readers in different world regions, and scale their global community.

Customize your user journey with WordPress VIP

Personalization will target different audience segments, empower your marketing teams to develop impactful messaging, and create a more streamlined user experience. The wide variety of tools provides flexibility for implementing a simple one-off feature or developing a comprehensive, feature-rich personalization platform.

Beyond the content personalization tools built into WordPress VIP, we have partnered with industry-leading technology companies to provide a powerful suite of customization tools.

Whether your organization is ready to expand its personalization capacity or is in the early stages of risk/benefit analysis, WordPress VIP experts are available to help. Get in touch to learn more.

Get the latest content updates

Want to be notified about new content?

Leave your email address and we’ll make sure you stay updated.