Skip to main content

Sources - Traffic Sources Read

Endpoint

/o?method=sources

Overview

Returns source-attribution metrics for the requested app and period, including normalized store/referrer values collected during ingest.

Authentication

Countly API supports three authentication methods:

  1. API key query parameter: api_key=YOUR_API_KEY
  2. Auth token query parameter: auth_token=YOUR_AUTH_TOKEN
  3. Auth token header: countly-token: YOUR_AUTH_TOKEN

Permissions

Requires sources Read permission.

Request Parameters

ParameterTypeRequiredDescription
methodStringYesMust be sources.
api_keyStringConditionalRequired if auth_token is not provided.
auth_tokenStringConditionalRequired if api_key is not provided.
app_idStringConditionalRequired for non-global-admin users during read validation.
periodStringNoStandard Countly period value (for example 7days, 30days, month, yesterday).
timezoneStringNoTimezone used for period calculations.
actionStringNoOptional mode switch. Use refresh for refresh-focused partial output.

Parameter Semantics

period values

The endpoint uses Countly's standard period parser. Common values include:

ValueMeaning
todayCurrent day window
yesterdayPrevious day
7days / 30days / 60daysRolling day windows
monthCurrent month
hourHour-level window
[start,end]Custom timestamp range (array form)

action

  • Omit action for full period output.
  • Use action=refresh for refresh-focused output used by dashboard refresh flows.

Configuration Impact

SettingDefaultAffectsUser-visible impact
sources.sources_length_limit100Ingest normalization before aggregationIncoming _store values are truncated to this max length, which can change source keys returned by this endpoint.

Response

Success Response

{
"2026": {
"2": {
"17": {
"sources": {
"com.android.vending": {
"t": 54,
"u": 41,
"n": 12
},
"direct": {
"t": 33,
"u": 28,
"n": 7
}
}
}
}
},
"meta": {
"sources": [
"com.android.vending",
"direct"
]
}
}

Response Fields

FieldTypeDescription
(root)ObjectRaw time-object response for sources metric.
{year}.{month}.{day}.sourcesObjectSource metric map for that time bucket.
...sources.{source}.tNumberTotal sessions/events for source in bucket.
...sources.{source}.uNumberUnique users for source in bucket.
...sources.{source}.nNumberNew users for source in bucket.
meta.sourcesArraySource keys present in returned dataset.

Error Responses

  • 400
{
"result": "Missing parameter \"api_key\" or \"auth_token\""
}
  • 400
{
"result": "Token not valid"
}
  • 401
{
"result": "No app_id provided"
}
  • 401
{
"result": "User does not have right"
}
  • 401
{
"result": "User does not exist"
}
  • 401
{
"result": "User is locked"
}
  • 401
{
"result": "App does not exist"
}
  • 401
{
"result": "Token is invalid"
}

Behavior/Processing

Behavior Modes

ModeTriggerProcessing PathResponse Shape
Standard readaction is not refreshValidates access and returns merged sources time-object for requested period.Raw root object with time buckets and meta.
Refresh readaction=refreshValidates access and returns refresh-focused subset for fast UI refresh.Raw root object with reduced slice and metadata.

Source Types Identified

Sources are grouped from the _store metric collected during session processing:

App TypeInput PatternStored Source Behavior
MobileStore/package value (for example com.android.vending)Stored as encoded source key and aggregated directly.
Mobile (fallback)_store missing and _os present_os is used as source value.
WebReferrer/source URLURL is normalized before storing source key.
WebNon-URL/non-domain valueTreated as direct/organic-style source label depending on consumer formatting.

Referrer Parsing Process (Web)

Before this endpoint reads source metrics, ingest logic normalizes web _store values:

  1. Removes protocol and leading www.
  2. Detects known search-engine hosts and keeps only allowed keyword query params.
  3. For non-search referrers, removes tracking tags like _ga, _gac, and utm_*.
  4. Trims trailing slash in plain host-style values.
  5. Applies sources_length_limit, then encodes value for storage.

This means response keys are normalized source/referrer identifiers, not always raw incoming referrer strings.

Impact on Other Data

  • Read-only endpoint. No collections are modified.

Database Collections

CollectionUsed forData touched by this endpoint
countly.membersAuthentication and permission checksReads member account, lock state, and feature-level app permissions.
countly.appsApp validation/context loadingValidates app_id and loads app timezone context for period calculations.
countly.sourcesSources analytics dataReads per-app source metric documents used to build response buckets.

Examples

Read source metrics for last 30 days

/o?
method=sources&
api_key=YOUR_API_KEY&
app_id=6991c75b024cb89cdc04efd2&
period=30days

Read source metrics in refresh mode

/o?
method=sources&
api_key=YOUR_API_KEY&
app_id=6991c75b024cb89cdc04efd2&
period=today&
action=refresh

Operational Considerations

  • Large periods return larger merged time objects and may increase payload size.
  • Refresh mode is intended for lightweight dashboard refreshes.

Last Updated

2026-02-17