Hi @laurens_hendrikx,
Using the raw data API (HTTP API — Piwik PRO Analytics Suite 16.40 documentation), one can retrieve the individual dimensions and metrics.
- Session ID is not a dimension you can retrieve vie the /query/ endpoint.
Both raw data session API as well as the raw data events API will return the column session_id.
You can use it to blend and calculate the data you require.
- You can either use the /query/ api to retrieve the required dimensions and metrics and let the calculation be done by Piwik PRO:
{
"date_from": "2023-01-01",
"date_to": "2023-12-31",
"website_id": "dae17aa5-85fe-412b-9f2e-4123bd52cd97",
"offset": 0,
"limit": 10,
"columns": [
{
"column_id": "referrer_type"
},
{
"column_id": "source"
},
{
"column_id": "medium"
},
{
"column_id": "campaign_name"
},
{
"column_id": "session_entry_url"
},
{
"column_id": "session_entry_title"
},
{
"column_id": "event_url"
},
{
"column_id": "event_title"
},
{
"column_id": "time_on_page"
},
{
"column_id": "is_bounce"
},
{
"column_id": "sessions"
}
],
"order_by": [
[
10,
"desc"
]
],
"filters": {
"operator": "and",
"conditions": [
{
"operator": "or",
"conditions": [
{
"column_id": "event_type",
"condition": {
"operator": "eq",
"value": 1
}
}
]
}
]
},
"metric_filters": null
}
If you need to filter based on campaign data only, you can use this:
{
"date_from": "2023-01-01",
"date_to": "2023-12-31",
"website_id": "dae17aa5-85fe-412b-9f2e-4123bd52cd97",
"offset": 0,
"limit": 10,
"columns": [
{
"column_id": "referrer_type"
},
{
"column_id": "source"
},
{
"column_id": "medium"
},
{
"column_id": "campaign_name"
},
{
"column_id": "session_entry_url"
},
{
"column_id": "session_entry_title"
},
{
"column_id": "event_url"
},
{
"column_id": "event_title"
},
{
"column_id": "time_on_page"
},
{
"column_id": "is_bounce"
},
{
"column_id": "sessions"
}
],
"order_by": [
[
10,
"desc"
]
],
"filters": {
"operator": "and",
"conditions": [
{
"operator": "or",
"conditions": [
{
"column_id": "event_type",
"condition": {
"operator": "eq",
"value": 1
}
}
]
},
{
"operator": "or",
"conditions": [
{
"column_id": "referrer_type",
"condition": {
"operator": "eq",
"value": 6
}
}
]
}
]
},
"metric_filters": null
}
You can basically build the report in Piwik PRO Analytics and check the API definition in the advanced section (as seen in the documentation: HTTP API — Piwik PRO Analytics Suite 16.40 documentation):
Keep in mind the offset and limit, in case you need to retrieve a lot of rows.
Sometimes it’s better to call the API multiple times (for instance because you want to know the bounce rate per campaign, instead of per campaign, per source, per medium, per entry page URL, etc…)
If you want to calculate it yourself, you can use the Raw data API and retrieve all the required dimensions and metrics, as documented here:
It will automatically return the session_id as part of the returned dataset, for both the events as well as the sessions API, so you can use it to blend the dataset.
Does this help?
Kind regards,
Richard