How to Create a Custom Viewed Page Metric

read
Last updated at:

Overview

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"}
]);
</script>
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:

<script>
var _learnq = _learnq || [];
var page = window.location.href;
_learnq.push(['track', 'Viewed Page',
{url: page}
]);
</script>

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 "?utm_email=youremail@example.com" 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.

Screen_Shot_2021-03-26_at_9.40.16_AM.png

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

x
Was this article helpful?
6 out of 10 found this helpful