How to create a custom viewed page metric

Last updated at:

You will learn

Learn how to create a custom Viewed Page metric by copying a code snippet to your site. The Viewed Page metric is similar to the Viewed Product metric, which tracks customer visits to product pages on your site. You might already be tracking the Viewed Product metric if you added the Viewed Product web tracking snippet when you integrated with your ecommerce platform. To track when your customers visit specific non-product pages on your site, follow the instructions outlined in this guide.

Installing the snippet

The following JavaScript code snippet to each page of your site that you want to track a Viewed Page metric for. This snippet will work for landing pages, in addition to other site pages.

1. Copy and paste the snippet below into your page files.

2. Then save and publish those files with the updated code.

<script type="text/javascript">
var _learnq = _learnq || [];
_learnq.push(['track', 'Viewed Page', {
PageName: "AboutUs"}
This will record a custom 'Viewed Page' metric in which the property name, ‘PageName’, equals the value, ‘AboutUs’.

3. You can substitute your page name(s) for the ‘AboutUs’ value between the quotation marks.

4. You can also change the ‘Viewed Page’ value to be ‘Visited Page’, ‘Tracked Page’, etc. by typing in the metric name you would like to use between those quotation marks.

5. If you would like to track Viewed Page by URL instead of by page title, you can use this alternate snippet below. Note that 'page you wish to track' should include the quotations and be the URL of the page you want to track.

var _learnq = _learnq || [];
var page = window.location.href;
_learnq.push(['track', 'Viewed Page',
{url: 'page you wish to track'}

Test your viewed page tracking

1. To test if your Viewed Page tracking is working, make sure that your page has been published and that you’ve amended "?" to your page’s URL to cookie yourself and track your activity.

2. After visiting your page, go into your Klaviyo account.

3. Navigate to Analytics > Metrics.

4. Search for Viewed Page (or, whatever alternative name you use for this metric). There, you will see if your Viewed Page metric activity has been pulled in. The Viewed Page metric tracks in real-time.

Example of the viewed page metric for an individual visitor

If you can view your activity, that means the metric is tracking successfully. If you don’t see your activity, try reloading the page in Klaviyo.

For Shopify stores: Based on your Customer Privacy settings in Shopify, Klaviyo may not track onsite events (including Active on Site, Viewed Product, and Viewed Page) for visitors to your Shopify store in the EU, EEA, UK and Switzerland, unless they have provided consent.

Additional resources

Was this article helpful?
34 out of 55 found this helpful