Get Session Data

Introduced in SDK v5.5.4

What this does (purpose):

Returns a JSON snapshot of the current app/session context that you can log, persist, or forward to your analytics pipeline. Useful for debugging attribution, personalizing screens, or attaching metadata to your own events.

Method

NotifyVisitorsApi.getInstance(context).getSessionData();

NotifyVisitorsApi.getInstance(context).getSessionData()

Typical usage (log the payload)

try {
    JSONObject j = NotifyVisitorsApi.getInstance(context).getSessionData();
    Log.d("App", "Session Data = " + j);
} catch (Exception e) {
    e.printStackTrace();
}

try {
    val j = NotifyVisitorsApi.getInstance(context).sessionData
    Log.d("App", "Session Data = $j")
} catch (e: Exception) {
    e.printStackTrace()
}

Example response

{
  "utm": {
    "Source": "(direct)",
    "campaign": "(direct)",
    "medium": "(none)",
    "keyword": "",
    "content": "(not set)",
    "Google_click_id": ""
  },
  "session": {
    "session_id": "u8rqPbALkFas0iXUPkhhvNWtbmudTkcg3ZKJDAdysZ2QZpny7Z",
    "session_count": "3",
    "user_type": "Unknown",
    "visit_type": "returning"
  },
  "location": {
    "country": "India",
    "city": "Aligarh",
    "region_code": "36",
    "continent_code": "AS"
  },
  "device": {
    "manufacturer": "Google",
    "model": "sdk_gphone64_x86_64",
    "carrier": "T-Mobile",
    "network_type": "WIFI",
    "wifi_enabled": true,
    "bluetooth_enabled": "Enabled"
  },
  "app": {
    "google_analytics_id": "bd4d1b45-5ded-42bd-93b6-8159b2a8091d",
    "ios_ifa": "",
    "screen_name": "Main Page",
    "sdk_version": "5.6.0"
  }
}