# How to Detect Session Startup and Shutdown in Ignition Perspective

**URL:** <https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875>\
**Category:** Ignition\
**Tags:** perspective, ignition81, scripting\
**Created:** [July 24, 2025, 7:01am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875 "2025-07-24T07:01:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 7:01am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/1 "2025-07-24T07:01:45Z")

</div>

Dear all,  
I would like to identify when a Perspective session (web page or app) starts up and shuts down.  
My goal is to write to a tag when the session starts and when it ends.  
I’ve tried using the session startup and shutdown events, but my script doesn’t seem to work.

Has anyone successfully used session startup or shutdown events in Perspective?  
Any suggestions or examples would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 24, 2025, 7:45am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/2 "2025-07-24T07:45:13Z")

</div>

> [@Sara](#):
>
> I’ve tried using the session startup and shutdown events, but my script doesn’t seem to work.

What happened exactly ? Got any errors in the logs ?  
Show us the scripts you used.

---

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 7:51am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/3 "2025-07-24T07:51:45Z")

</div>

Nope, i don't see the logfile. I try to write a memory tag to control the events:

 ![Screenshot 2025-07-24 094953](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/4/d480b62412c02d851ef81b2b6423c341caf4619f.png)

 ![Screenshot 2025-07-24 095041](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/b/dbf43cb806d87bf9f83ba6d8a66a33f93a1d4134.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 24, 2025, 7:54am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/4 "2025-07-24T07:54:17Z")

</div>

Add some logging to both events and make sure you see a corresponding entry in the logs (go to your gateway's webpage, and find the log page. It's in the "status" section).

---

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 8:06am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/5 "2025-07-24T08:06:21Z")

</div>

Is there a script instruction to identify and use the idsession?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 24, 2025, 8:11am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/6 "2025-07-24T08:11:37Z")

</div>

I'm not sure what you mean. You have direct access to session properties in the session events.

```python
logger = system.util.getLogger("SessionStartup")
logger.infof("started session %s", session.props.id)

```

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/a/fa6b68051504d90d0481afedf3948cd19be85f4b.png)

---

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 8:22am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/7 "2025-07-24T08:22:40Z")

</div>

ok your instruction works but i would like to use the relevant id session to write a tag

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 24, 2025, 8:38am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/8 "2025-07-24T08:38:38Z")

</div>

You're gonna have to be more explicit than that.

Actually, what are you trying to solve ? What's the end goal ?

---

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 8:53am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/9 "2025-07-24T08:53:35Z")

</div>

Apologies for the confusion — my end goal is to write to a specific tag when a particular session is closed. I tried several if instructions but the ones I really need don't work

 ![Screenshot 2025-07-24 115414](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/a/4a6881e967d6b2ecf3c835664f7ccd99eae9e564.png)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 24, 2025, 10:40am UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/10 "2025-07-24T10:40:10Z")

</div>

Are you sure the session had closed when you checked? Have a look in the status page of the Web portal at the perspective sessions running. A session does not end simply when you close the browser tab running a client. After that it waits for the session timeout before the session running in the gateway shuts down

---

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 12:41pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/11 "2025-07-24T12:41:56Z")

</div>

Yes, you are right but I'm sure of the closed session, i see the log view and there are all the session, and when the script doesn't work.

 ![Screenshot 2025-07-24 142401](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/8150c88ef583cda9784c3065cf3691047864d44e.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 24, 2025, 12:45pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/12 "2025-07-24T12:45:01Z")

</div>

~~Nick's point is that closing a browser tab, or closing the browser entirely, **does not end** the session. Browsers don't tell webservers when they close, so the gateway **cannot** close the session immediately. It has to time out.~~

 

~~Your desire to act on session close is misguided/impractical. Find another way. (Share **why** you think you need this.)~~

Your script has a syntax error. Case-sensitive variable name, it seems.

---

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 12:50pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/13 "2025-07-24T12:50:33Z")

</div>

I agree. For me is ok that the script running when the timeout expires.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 24, 2025, 12:57pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/14 "2025-07-24T12:57:05Z")

</div>

`s['userAgent']` is not where you check for whether the session is a designer or not. You would check`s['sessionScope']` instead.

Don't post images of scripts, post the script itself, and format it with the `</>` button.

| Key | Description | Value |
| --- | --- | --- |
| userAgent | Details about the device or browser running the Session. | String |
| id | The Session ID (or Designer ID if called from the Designer). | String |
| username | The logged-in user's name or Unauthenticated if the Session is not authenticated. | String |
| project | The name of the project active in the Session. | String |
| uptime | The time (in milliseconds) the Session has been active since creation. | Integer |
| clientAddress | The IP address or hostname of the client running the Session. | String |
| lastComm | The time (in milliseconds) since the last communication with the Gateway. | Integer |
| sessionScope | The environment where the Session is running: Designer, Browser, iOS, or Android. | String |
| activePages | The number of pages currently active in the Session. | Integer |
| recentBytesSent | The number of bytes sent to the Gateway in teh most recent communication. | Integer |
| totalBytesSent | The total number of bytes sent to the Gateway by the Session. | Integer |
| pageIds | A list of the IDs of pages currently open in the Session. | List |
| authorized | Whether the user was authorized when the Session data was retrieved (True or False) | Boolean |

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 24, 2025, 12:57pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/15 "2025-07-24T12:57:27Z")

</div>

> [@pturmel](#):
>
> Case-sensitive variable name

Are you talking about the "ProjectFilter" arg name? I can't find anything else 🤔

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 24, 2025, 12:58pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/16 "2025-07-24T12:58:34Z")

</div>

I think he is talking about `sessionID` vs `sessionId`, it's commented out.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 24, 2025, 1:02pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/17 "2025-07-24T13:02:24Z")

</div>

> [@dkhayes117](#):
>
> it's commented out.

To get that logged error, a similar usage must have been present.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 24, 2025, 1:04pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/18 "2025-07-24T13:04:36Z")

</div>

Right, and it is commented as `this line doesn't work`. I was just pointing Nick where to look.

---

<div class="post-metadata">

**Author:** ![Sara](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Sara](https://forum.inductiveautomation.com/u/Sara)\
**Post date:** [July 24, 2025, 1:22pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/19 "2025-07-24T13:22:25Z")

</div>

ok i correct the second one sessionId, but the if instruction doesn't work

 ![Screenshot 2025-07-24 151732](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/01155e106cb30420ce84362425b9d8006110b8c6.png)

 ![Screenshot 2025-07-24 151900](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e45c84624c08d852a830ad60ca55c5d0b52c3ff2.png)

now my test tag values 200. but if it works well would value 1000

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 24, 2025, 11:13pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-session-startup-and-shutdown-in-ignition-perspective/108875/20 "2025-07-24T23:13:45Z")

</div>

To answer _why_ your script isn't working though: when the shutdown event fires, the session is _already gone_, so `getSessionInfo` doesn't contain the session anymore

Going back a step though, with the actual code you've got, it seems superfluous to be looping through the sessions _at all_, when at the end of it all it's doing is writing the session id to a tag. Can't you just skip the loop and just write the session.props.id to the tag? Unless of course there's some other logic you want to do that you haven't shown.
