Solved

How do page view events get identified?

  • 10 January 2023
  • 2 replies
  • 183 views

Badge

Hello there,
It seems that there are duplicate page view events and definitions firing as we navigate to different pages within our site.
To get to the root cause of the duplicate page view events, we'd like to learn more about how page view events are identified on Heap.
For example, are page view events detected via a URL change or when a load event (or any other event) is fired on the window?
We'd like more detail on how these page view events are triggered and what goes on in the background to have them identified within Heap.
Thank you.

icon

Best answer by Rohin-Heap 14 January 2023, 05:44

View original

2 replies

Userlevel 2
Badge +1

Hello Judy,

Great question!  The pageview event is fired whenever a pushState for the URL has occurred. You can read more about pushStates here but it’s primarily when the URL changes. This means if the Hash parameters change, query parameters change or any portion of the URL will count as a new pageview.  

Let me know if that helps!

Userlevel 5
Badge +3

@judy I wanted to add a little more color. There are 3 different ways Heap registers a pageview: 

  1. DOMContentLoaded event
  2. pushState changes
  3. hash route changes

#2 and #3 are flavors of each other, and are primarily used in Single Page Apps. #1 is the event that fires in “normal” websites, and when you first land on a site or when you hit the refresh button in either SPA or non-SPA sites.

If you’re seeing what seems like duplicates in Heap, query string changes are a common culprit. e.g. a search or collections page on an E-comm site that has filters which update the query string. The path stays the same, but the url, and the page contents, are actually changing. Another common gotcha to watch out for is if you have a page with lots of anchor tags (e.g. an FAQ page, or a documentation) as those will also count as pageviews, but the path will stay the same.

Reply