How to create a custom viewed page metric

Last updated at:

You will learn

In this article, you will 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 needs to be added 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.

Copy and paste the snippet below into your page files, and 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’. You can substitute your page name(s) for the ‘AboutUs’ value between the quotation marks. 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.

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

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.

After visiting your page, go into your Klaviyo account. Navigate to Analytics > Metrics, and 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.


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.

Additional Resources

Was this article helpful?
26 out of 41 found this helpful