Set Up Recommendation Tracking
Why tracking is the foundation of recommendations
Section titled “Why tracking is the foundation of recommendations”Content Recommendations learns what to suggest by observing what visitors read and how content relates to other content. Without tracking, the recommendation engine has no behavioral data and no content metadata to work with. The result is an empty or random set of suggestions.
Tracking collects two things: visitor behavior (which pages they view, how long they stay) and content properties (what each page is about). Together, these power the algorithms that match visitors to relevant content.
What you will do
Section titled “What you will do”- Add the tracking script to your site
- Configure content properties for your pages
- Send page view events
- Verify data collection
Add the tracking script
Section titled “Add the tracking script”The Content Recommendations tracking script must load on every page where you want to track behavior or display recommendations.
<!-- Place in the <head> of your site -->
<script>
(function(d, s) {
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s);
j.async = true;
j.src = 'https://codegen.optimizer.net/YOUR_ACCOUNT_ID/loader.js';
f.parentNode.insertBefore(j, f);
})(document, 'script');
</script> Replace YOUR_ACCOUNT_ID with your Content Recommendations account identifier. You can find this in your Optimizely dashboard under Content Recommendations > Settings > Account.
Placement matters. Add the script to the <head> section so it loads before the page content renders. This ensures tracking captures the full page view and content properties are available when the recommendation engine processes the page.
Configure content properties
Section titled “Configure content properties”Content properties tell the recommendation engine what each page is about. The engine uses these properties to build content profiles and calculate similarity between pages.
Required properties
Section titled “Required properties”Every tracked page must send these properties:
| Property | Description | Example value |
|---|---|---|
title | The page title | ”How to Optimize Landing Pages” |
type | Content category or type | ”blog-post”, “product-page”, “guide” |
url | Canonical URL | ”https://example.com/blog/optimize-landing-pages” |
Recommended properties
Section titled “Recommended properties”Additional properties improve recommendation quality:
| Property | Description | Example value |
|---|---|---|
categories | Topic categories | [“marketing”, “conversion”] |
tags | Content tags | [“landing-pages”, “optimization”, “CRO”] |
author | Content author | ”Jane Smith” |
publishDate | Publication date | ”2026-03-15” |
language | Content language | ”en” |
image | Featured image URL | ”https://example.com/images/hero.jpg” |
Set content properties in code
Section titled “Set content properties in code”// Set content properties before sending the page view
window.optimizelyContentRecs = window.optimizelyContentRecs || [];
window.optimizelyContentRecs.push({
action: 'setContentProperties',
properties: {
title: document.title,
type: 'blog-post',
url: window.location.href,
categories: ['marketing', 'conversion'],
tags: ['landing-pages', 'optimization'],
author: 'Jane Smith',
publishDate: '2026-03-15',
language: 'en',
image: 'https://example.com/images/hero.jpg',
},
}); Content properties for CMS-rendered pages
Section titled “Content properties for CMS-rendered pages”If your site renders content from CMS, extract properties from the rendered page data rather than hardcoding them:
// Example: extract properties from page metadata
function getContentProperties() {
const meta = (name) => {
const el = document.querySelector(`meta[name="${name}"]`);
return el ? el.content : null;
};
return {
title: document.title,
type: meta('content-type') || 'page',
url: document.querySelector('link[rel="canonical"]')?.href
|| window.location.href,
categories: meta('categories')?.split(',').map(c => c.trim()) || [],
tags: meta('keywords')?.split(',').map(t => t.trim()) || [],
author: meta('author'),
publishDate: meta('publish-date'),
language: document.documentElement.lang || 'en',
};
}
window.optimizelyContentRecs = window.optimizelyContentRecs || [];
window.optimizelyContentRecs.push({
action: 'setContentProperties',
properties: getContentProperties(),
}); Send page view events
Section titled “Send page view events”After setting content properties, send a page view event to record the visit.
window.optimizelyContentRecs.push({
action: 'trackPageView',
}); For single-page applications (SPAs) that do not reload the page on navigation, send a page view event on each route change:
// Call on each route change
function trackSpaPageView(contentProperties) {
window.optimizelyContentRecs = window.optimizelyContentRecs || [];
// Update content properties for the new page
window.optimizelyContentRecs.push({
action: 'setContentProperties',
properties: contentProperties,
});
// Send the page view
window.optimizelyContentRecs.push({
action: 'trackPageView',
});
} Verify data collection
Section titled “Verify data collection”After deploying tracking code, confirm that data is flowing correctly.
Check the browser console
Section titled “Check the browser console”- Open your site in a browser with developer tools open
- Navigate to a tracked page
- In the Network tab, filter for requests to
optimizer.net - Verify that you see a tracking request with a
200response - Inspect the request payload to confirm content properties are present
Check the Optimizely dashboard
Section titled “Check the Optimizely dashboard”- Navigate to Content Recommendations > Content
- Wait 15-30 minutes for initial data processing
- Verify that tracked pages appear in the content list
- Click a page to confirm its properties match what you configured
Troubleshooting
Section titled “Troubleshooting”| Issue | Cause | Fix |
|---|---|---|
| No tracking requests in Network tab | Script not loading or blocked by ad blocker | Verify script placement; test with ad blocker disabled |
| Tracking request returns 403 | Invalid account ID | Check the account ID in the loader URL |
| Pages not appearing in dashboard | Data processing delay or missing required properties | Wait 30 minutes; verify title, type, and URL are set |
| Properties showing as empty | Properties set after page view event | Set content properties before calling trackPageView |
| SPA page views not tracking | Page view not fired on route change | Add route change listener that calls trackPageView |