Log Perspective Session Stats

Is there any way to log the data we get from the Perspective Session Stats?

We’d like to be able to see how often specific pages get viewed.

If you only care about a few, it’s fairly easy. If you want an in-depth idea of how often each View is loaded, that’s far more difficult because you have to insert the same logic for EVERY View you want tracked.

For Views:
In the onStartup Event of the View, use your chosen record-keeping tactic (probably a dDB update query), but you’ll need to hard-code the View’s path. You could supply self.page.props.primaryView, BUT this will only be accurate if the View is only ever used as a primary View (not as a Popup, Docked View, or embedded in any way)

For Pages:
There is a Page onStartup Event in versions 8.0.16 and newer which allows you to hook into the startup of a Page. To be clear, “Page” is a loosely-based term here - what you’re really hooking into is the startup of the browser tab. Due to this, the Page onStartup is only called in certain situations, which is supposed to be documented here (it’s not right now, but I’ve reached out to the documentation team to update it). This event has access to the path of the Page at Startup, but not the View.

Ok I see. So the Gateway doesn’t do any record-keeping itself. Just lists the active perspective sesions and their details?

Thanks for that info! Most of the views we care about are actually the primaryView-- so using the self.page.props.primaryView would work. Could you detail that method a bit more? Where would I write that db update script?

Correct. What you see when you visit the Status > Perspective Sessions page in the Gateway is just a current snapshot - there’s no tracking or record-keeping going on at this time.

Your database contains a table named “persp_stats”, which has at least two columns: “visits” and “view_path”.
The View which you would like to track already has an entry in persp_stats where you have supplied the path to the View within the project.

Select and open the View node which you would like to track in the Project Browser, then right-click the View node and select “Configure Events”.
Select the “onStartup” Event and select a Script Action to be invoked.
You might need to tinker with the SQL a bit depending on your database flavor, but this should in theory do what you’d like.

Ok so I still need to attach this script to the startup event for every view I’m interested in.

Yes - any View you want to track needs to have that script. Due to this, you should probably configure the Database name as a tag read where you store the database to be used. Doing so would prevent you from needing to update X number of scripts should you ever change the DB. Alternatively, you could switch it to system.pdb.runNamedQuery() and then you could just update the Named Query (preferable).

Is there some inbuilt feature in perspective where I can do some basic web-traffic analysis like

  • Number of visits

  • Avg duration per visit

  • Bounce rate

  • Hours spent on a page/view

If there is no direct option, any guidance on how can I proceed with custom queries and a database arrangement for these?

Thanks, and Cheers