cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
yngwie_lucero
Dynatrace Advisor
Dynatrace Advisor

How to tag a user in a session 

A session gets tagged when SDK API method is called.

Dynatrace.identifyUser("john.doe@example.com");

for both Android and iOS.

Session is not being tagged?

Review the logs.

From the Application => Mobile app settings => Instrumentation settings.

If opt-in mode is enabled

 
mceclip0.png

Make sure that, for iOS, in the plist DTXUserOptIn is set to true or, for Android, in the configuration file that userOptIn  set to true

From Logs iOS: DTXUserOptIn , value: 1, Android : userOptIn=true

Confirm that the application code has the privacy notice added so users can set their preferences. Example here.


iOS

import Dynatrace

// Privacy settings configured below are only provided
// to allow a quick start with capturing monitoring data.
// This has to be requested from the user
// (e.g. in a privacy settings screen) and the user decision
// has to be applied similar to this example.
let privacyConfig = Dynatrace.userPrivacyOptions()
privacyConfig.dataCollectionLevel = .userBehavior
privacyConfig.crashReportingOptedIn = true
privacyConfig.crashReplayOptedIn = true
Dynatrace.applyUserPrivacyOptions(privacyConfig) { (Bool) in
// callback after privacy changed
}

Android

// Privacy settings configured below are only provided
// to allow a quick start with capturing monitoring data.
// This has to be requested from the user
// (e.g. in a privacy settings screen) and the user decision
// has to be applied similar to this example.
Dynatrace.applyUserPrivacyOptions(UserPrivacyOptions.builder()
.withDataCollectionLevel(DataCollectionLevel.USER_BEHAVIOR)
.withCrashReportingOptedIn(true)
.build());

These parts of code can be found in Application => Mobile app settings => Instrumentation wizard for each platform.

DataCollectionLevel meanings

  • OFF (the agent does not capture data.)
    from logs will be referenced to iOS:  dataCollectionLevel:0, Android: dataCollectionLevel=OFF
  • PERFORMANCE (the agent only captures anonymous performance data.)
    from logs will be referenced to iOS:  dataCollectionLevel:1, Android: dataCollectionLevel=PERFORMANCE
  • USER_BEHAVIOR (he agent captures performance and user data.)
    from logs will be referenced to iOS:  dataCollectionLevel:2, Android: dataCollectionLevel=USER_BEHAVIOR

In this situation, USER_BEHAVIOR is the only status in which the user will be tagged.


 IOS

Search in the xcode console logs for the following, Here "Kazuya" name is tagged.

CREATED IDENTIFY_USER EVENT: <DTXMeasurement 0x7fcd89521410: visitorId=7868376413403 sessionId=12 sessionSequence=0 name=Kazuya startTimestamp=2021-08-19 14:13:56 +0000 customValue=0 duration=0.000000 sent=0 connectionType=w networkProtocol=802.11x batteryStrengthPercent=-2 freeMemoryPercent=0 activeMemoryPercent=42 inactiveMemoryPercent=42 wiredMemoryPercent=9 portraitOrientation=1 currentTag=-1 enclosingTag=0 customValueDouble=0.000000 eventType=60 self.eventTypeString=IdentifyUser lifecycleSequence0=18 lifecycleSequence1=0 lifecycleSequence2=0 lifecycleSequence3=0 threadId=1 bytesReceived=0 bytesSent=0 >

 

Android

In this example, the application user is tagged with "Ace Ventura" and the corresponding log entry can be found in Logcat (either in Android Studio or with the adb logcat command-line tool)

2021-08-19 11:41:59.818 10455-10455/com.dynatrace.mobilelab D/dtxAgentCore

NOTE:
Changing the data collection level will generate a new user session. Meaning whenever the value changes the current session will end and a new one is created.

 

Some sessions are anonymous?

So if we are sure that the Dynatrace.identifyUser is being called and sometimes users are not tagged.

We have to confirm that this line of code "Dynatrace.identifyUser" is being called.

An easy way to do that is to print in the log a custom message

Example:

print("***WILL START TAGGING***")
Dynatrace.identifyUser("john.doe@example.com");
print("***Tagged the user***")

If you don't see the printed parts in the logs, then identifyUser was never called.


Also, make sure that the passed variable to identify the user is not null or empty (simply by printing its value to the logs.)

If you pass a null or empty string to Dynatrace.identifyUser(""); the sessions won't be tagged.

Tracking a session from logs to Dynatrace?

From iOS logs:

Here the visitor ID is 14054083387977

 
sessionID.png

From the logs search for visitorID: <visitorID>

2021-08-23 14:29:40.045093+0200 DynaPods[7304:249306] 🔼 FINE    📡 Communication  [DTXCommunicationsManager.m:1118-12803-2] sendMetrics for visitorId: 14054083387977 sessionId: 151, number of metrics to send: 12

From Android logs:

Here the visitor's session ID is 3672025434

From the logs at the beacon search for vi=<visitorID>

#12712.aPOST url[https://bf62926nek.bf.dynatrace.com/mbeacon?type=m&srvid=3&app=012cb464-3e06-4454-ada1-db0ec2db871a&va=8.217.1.1003&tt=maandroid&pt=0&resp=json&cts=1625491826087&si=3672025434_4] data[vv=3&va=8.217.1.1003&ap=012cb464-3e06-4454-ada1-db0ec2db871a&an=MySafaricom&ai=com.safaricom.mysafaricom&vn=1.8.0-beta-rc01&vb=10816&vi=3672025434&sn=4&ss=0&rm=1850&cp=ARMv7+rev+4+%28v7l%29&os=Android+10&mf=HMD+Global&md=Nokia+2.4&rj=g&ul=en_GB&sw=720&sh=1600&sd=280&pt=0&so=p&bl=100&fm=723&cr=SAF+FOR+YOU&ct=w&np=802.11x&tt=maandroid&dl=2&cl=2&vs=2&fv=pl&tv=1625

or if there is a web request that is tagged by the android agent via MT_<visitorID>

 

Mobile Sessions are split:

  • On app termination.
  • On 30 minutes of inactivity.
  • After 6 hours of duration.
  • On more than 200 user actions.

    The inactivity timeout (10 min) is controlled by the Agent. When the app foregrounds it checks if the inactivity timeout was reached and creates a new session or continues the existing one (if the app was not purged from memory by the mobile OS when in the background). Session timeout is, also, enforced on the cluster if not done on a mobile device (~35 min by visit store).
Version history
Last update:
‎03 Jan 2023 09:57 AM
Updated by:
Comments
ChadTurner
DynaMight Legend
DynaMight Legend

Great Write up @yngwie_lucero