javascriptgoogle-analyticsgoogle-analytics-apigoogle-analytics-4mixpanel

Why do UI analytics libraries separate pageview events from other events?


Most UI analytics libraries (e.g googleAnalytics) seem to differentiate between tracking pageViews and other events.

For example, this is from the Google Analytics page.

The Google Analytics client side browser plugin works with these analytic api methods:

analytics.page - Sends page views into Google Analytics

analytics.track - Track custom events and send to Google Analytics

Why can’t a pageView be considered just another event such as a click, a loginEvent, etc?

This would eliminate the need for the analytics.page method.


Solution

  • There's no real technical need to separate them since the payload of an event is of the same structure. Even if you look at the network request sent, you're likely to notice that page/screenview events are exactly the same as normal events, maybe lacking a few dimensions if anything but that's it.

    It's mostly due to how the business sees and analyses these. The core reason for it is that events are seen to be fired in a context of a page. It's very common for the business to analyze what pages the events have fired on. Even though you can normally override the page/screen dimension of an event, a tracking library will tend to inject the last page/screen that was sent with the page/screen track method.

    So it looks something like this with default tracking:

    Event 0: page null
    Page A
    Event 1: page A
    Event 2: page A
    Event 3: page A
    Page B
    Event 4: page B
    Event 5: page B
    Page C
    Page D
    Event 6: page D
    

    Now if Pages and Events would be in the same method, the whole page dimension inheritance would have to be implemented differently.

    Moreover, there are small technical details like the method can throw an error or a warning when the client attempts to send a pageview/screenview event with no page/screen dimension set. Or issue warnings when sending repeated page events with the same dimension as the previous one.