# Log Perspective Session Stats

**URL:** <https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 18, 2020, 1:48pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834 "2020-09-18T13:48:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sydney.bergeron](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sydney.bergeron](https://forum.inductiveautomation.com/u/sydney.bergeron)\
**Post date:** [September 18, 2020, 1:48pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834/1 "2020-09-18T13:48:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 18, 2020, 4:14pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834/2 "2020-09-18T16:14:36Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC80/Perspective+Session+Event+Scripts) (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.

---

<div class="post-metadata">

**Author:** ![sydney.bergeron](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sydney.bergeron](https://forum.inductiveautomation.com/u/sydney.bergeron)\
**Post date:** [September 18, 2020, 4:31pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834/3 "2020-09-18T16:31:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 18, 2020, 4:47pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834/4 "2020-09-18T16:47:31Z")

</div>

> [@sydney.bergeron](#):
>
> So the Gateway doesn’t do any record-keeping itself. Just lists the active perspective sesions and their details?

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.

> [@sydney.bergeron](#):
>
> Where would I write that db update script?

**Preconditions:**  
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.

**Setup:**  
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.

 ![Screen Shot 2020-09-18 at 9.42.17AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/9/c97c43569c1f5357b728f03d6fa7dfcf9fb4ce72.png)

---

<div class="post-metadata">

**Author:** ![sydney.bergeron](https://avatars.discourse-cdn.com/v4/letter/s/779978/32.png) [@sydney.bergeron](https://forum.inductiveautomation.com/u/sydney.bergeron)\
**Post date:** [September 18, 2020, 6:14pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834/5 "2020-09-18T18:14:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 18, 2020, 6:17pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834/6 "2020-09-18T18:17:01Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [May 12, 2021, 2:42pm UTC](https://forum.inductiveautomation.com/t/log-perspective-session-stats/38834/7 "2021-05-12T14:42:48Z")

</div>

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  
Sam
