Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Any APIs that we can use to separate two SESSIONS?


#1

As New Relic defines a mobile session as beginning when an app appears on screen and ending when the app is sent to the background. Now we met an issue to get the SESSION number for our own requirement: in our iOS App, suppose the screen always stays on foreground, and use account A to sign into our App then signs out, after that, use account B to sign into the App, actually we need to take this as two different sessions but currently as the app stays on the foreground, it only was calculated as one SESSION. how can we implement that or any defined APIs that we can use to separate the two SESSIONS in such kind of scenario? Thanks in advance.


#2

Hi, @lvjianh: You may capture the user ID as a custom attribute. Then, in Insights, rather than querying for the number of session IDs, you may query for the number of unique user IDs:

SELECT uniqueCount(userId) FROM MobileSession


#3

Hello @philweber, yes, we add custom attribute userId to identify the user. But the query result is the number of unique user, not session.
Now we met an issue to get the SESSION number for our own requirement: in our iOS App, suppose the screen always stays on foreground, and use account A to sign into our App then signs out, after that, use account B to sign into the App, actually we need to take this as two different sessions but currently as the app stays on the foreground, it only was calculated as one SESSION for user B, the session and other info for the user A are missing.

How can we implement that or any defined APIs that we can use to separate the two SESSIONS in such kind of scenario? Thanks in advance.


#4

@lvjianh, it is not possible to “split” the session created by New Relic. Since you’d like to designate the session differently, I suggest using a custom session attribute for your own custom session id. This attribute can then be set at user login.


#5

Hello @spotts @philweber, yes, we have add a new custom attribute newSessionId(User Uuid + timestamp) to distinguish the sessions in above scenarios. We expected that newSessionId A for user A and newSessionId B user B were all stored in the New Relic Insights, but actually only the newSessionId B was calculated, the newSessionId A was missing. Could you help debug the issue on New Relic version 5.14.o for IOS? or please help forward the issue to provide New Relic ticket. Thanks in advance.


#6

This is related to the timing of when the events occur and when they are harvested. By default event data is harvested every 10 minutes or when the app is sent to background. What is likely happening here is that user B is logging in before the events are harvested. For session attributes this means the attribute will be overwritten.

In this scenario, it may be better to create a custom event for this attribute. Custom events will be created individually with the attribute at that time as apposed to session attributes which overwrite to the most recent value. We have a Mobile Level-up post which discusses the differences between using a session attribute and a custom event attribute which you may find helpful.

You can also increate the harvest time for events to as often as once a minute. This is done by setting setMaxEventBufferTime. This configuration should be placed in the applicationDidBecomeActive method to ensure it is set when the app is active.