# Resolve User Tagging Issues for Android and iOS in Dynatrace

**URL:** <https://community.dynatrace.com/t/resolve-user-tagging-issues-for-android-and-ios-in-dynatrace/37600>\
**Category:** Troubleshooting\
**Tags:** android, mobile-monitoring, ios\
**Created:** [January 3, 2023, 2:41am UTC](https://community.dynatrace.com/t/resolve-user-tagging-issues-for-android-and-ios-in-dynatrace/37600 "2023-01-03T02:41:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yngwie\_lucero](https://avatars.discourse-cdn.com/v4/letter/y/3d9bf3/32.png) [@yngwie\_lucero](https://community.dynatrace.com/u/yngwie_lucero)\
**Post date:** [January 3, 2023, 2:41am UTC](https://community.dynatrace.com/t/resolve-user-tagging-issues-for-android-and-ios-in-dynatrace/37600/1 "2023-01-03T02:41:46Z")

</div>

_Summary:&nbsp;This article explains common reasons why user tagging may fail in mobile applications. It outlines configuration steps, SDK considerations, and platform‑specific tagging behaviors._

## How to tag a user in a session&nbsp;

A session gets tagged when SDK API method is called.

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

```

for both Android and iOS.

## Session is not being tagged?

Review the logs.

From the&nbsp; **Application =\> Mobile app settings** &nbsp;=\>&nbsp; **Instrumentation settings.**

If opt-in mode is enabled

 ![mceclip0.png](https://global.discourse-cdn.com/dynatrace/original/3X/1/7/174a15c18235727fd2d19b60bd697b1a7406611d.png)

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

From Logs&nbsp; **iOS** : DTXUserOptIn , value: 1,&nbsp; **Android** &nbsp;:&nbsp;userOptIn=true

Confirm that the application code has the privacy notice added so users can set their preferences. Example&nbsp;[here](https://dt-url.net/bq5m0pnm).

### iOS

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

```

### Android

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

```

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

### DataCollectionLevel meanings

- OFF (the agent does not capture data.)  
from logs will be referenced to&nbsp; **iOS** :&nbsp; dataCollectionLevel:0,&nbsp; **Android** : dataCollectionLevel=OFF
- PERFORMANCE (the agent only captures anonymous performance data.)  
from logs will be referenced to&nbsp; **iOS** :&nbsp; dataCollectionLevel:1,&nbsp; **Android** : dataCollectionLevel=PERFORMANCE
- USER\_BEHAVIOR (he agent captures performance and user data.)  
from logs will be referenced to&nbsp; **iOS** :&nbsp; dataCollectionLevel:2,&nbsp; **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"** &nbsp;name is tagged.

```auto
CREATED IDENTIFY_USER EVENT: <DTXMeasurement 0x7fcd89521410: visitorId=7868376413403 sessionId=12 sessionSequence=0 name=<strong>Kazuya</strong><span> 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 ></span>

```

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)

```auto
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:**

```auto
print(" ***WILL START TAGGING***")<br>Dynatrace.identifyUser("john.doe@example.com");<br>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&nbsp; **null** &nbsp;or&nbsp; **empty** &nbsp;(simply by printing its value to the logs.)

If you pass a null or empty string to&nbsp;**Dynatrace.identifyUser(“”);**&nbsp;the sessions won’t be tagged.

## Tracking a session from logs to Dynatrace?

From iOS logs:

Here the visitor ID is&nbsp; **14054083387977**

 ![sessionID.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/2/e205af0442cc3e703798968b51a75a7941045084.png)

From the logs search for visitorID: \<visitorID\>

```auto
<strong><span>2021-08-23 14:29:40.045093+0200 DynaPods[7304:249306] 🔼 FINE</span><span class="">    </span>📡 Communication<span class="">  </span>[DTXCommunicationsManager.m:1118-12803-2] sendMetrics for visitorId: 14054083387977 sessionId: 151, number of metrics to send: 12</strong>

```

From Android logs:

Here the visitor’s session ID is&nbsp; **3672025434**

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

```auto
#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&nbsp; **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.

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [January 10, 2023, 3:11pm UTC](https://community.dynatrace.com/t/resolve-user-tagging-issues-for-android-and-ios-in-dynatrace/37600/2 "2023-01-10T15:11:23Z")

</div>

Great Write up&nbsp;[@yngwie\_lucero](https://community.dynatrace.com/user/24673)
