Issue getting Campaigne statistic thought api


Hello Mautic Community,

I hope you’re all doing well. I’m currently facing an issue retrieving campaign statistics via the API. I’ve tried using the endpoints api/stats and api/campaigns, but I haven’t been successful in accessing the specific statistics related to a campaign.

Has anyone encountered this issue before or found a reliable solution? I’d greatly appreciate any guidance or suggestions you could share.

Thank you in advance for your help and support

Hello,

You can get the list of available stats tables here:

And this is how you pull the data:

Regards:
Joey

Hi folks,

Just to add that the most up to date content is at

The old docs at developer.mautic.org are there for legacy purposes, as we haven’t pulled all the content over yet, so there might be some content which is missing but the new devdocs site is the current one.

1 Like

Thanks for your reply @joeyk I’m able to access some stats endpoint, but I’m still not getting the specific stats related to actions and decisions made within a particular campaign. I’ve gone through all the available stats tables, but none seem to show this information.

Below is the available table
“availableTables”: [
“asset_downloads”,
“audit_log”,
“campaign_lead_event_log”,
“campaign_leads”,
“channel_url_trackables”,
“companies_leads”,
“dynamic_content_lead_data”,
“dynamic_content_stats”,
“email_stat_replies”,
“email_stats”,
“email_stats_devices”,
“focus_stats”,
“form_submissions”,
“ip_addresses”,
“lead_categories”,
“lead_companies_change_log”,
“lead_devices”,
“lead_donotcontact”,
“lead_event_log”,
“lead_frequencyrules”,
“lead_lists_leads”,
“lead_points_change_log”,
“lead_stages_change_log”,
“lead_utmtags”,
“page_hits”,
“page_redirects”,
“point_lead_action_log”,
“point_lead_event_log”,
“push_notification_stats”,
“sms_message_stats”,
“stage_lead_action_log”,
“tweet_stats”,
“video_hits”,
“webhook_logs”
],

Any further insights would be greatly appreciated

Hey,

Conditions and decisions are stored not as simly readable statistics, but as an entry as “Yes branch choosen” for example. Or event completed time / event scheduled time.
You will need to build the stats from these building blocks.
Just look at the campaign related tables to understand the logic.

Joey

Okay thanks @joeyk so you mean the “campaign_leads” table right. What about this api /api/campaigns/events?

I think that is just for listing the events.
You would need to pull the data from the campaign_lead_event_log.
Each line is an event with scheduled date, completed date, yes/no path taken, etc.

I used the endpoint api/stats/campaign_lead_event_log, but the sample data I received doesn’t include any fields related to email opens or clicks, nor any values like "yes" in the JSON response.

{
        "id": "41230",
        "event_id": "128",
        "lead_id": "855",
        "campaign_id": "41",
        "rotation": "1",
        "date_triggered": "2024-05-27 13:58:03",
        "is_scheduled": "0",
        "system_triggered": "1",
        "metadata": "a:2:{s:6:\"failed\";i:1;s:6:\"reason\";s:37:\"165.154.164.142 has no email address.\";}",
        "channel": "email",
        "channel_id": "3",
        "non_action_path_taken": "0"
    },

There is no ‘click’ and ‘open’ for campaigns.
There is for Emails, you need to look in your email_stats table.

How exactly your report should look like?

Thanks once again for your reply. I will like to obtain specific statistics for the campaign—namely, the number of emails sent and the related interactions (opens, clicks, and page visits) like on the screenshort above for that particular campaign via an API. in resume decision, action and contact

Hi,

you need to consrtuct this yourself by using the campaign_lead_event_log (for decisions), email_stats table (for email statistics), url_redirects and page_views (for clicks).

Check the tables above and you’ll see how it works.
Joey

Thanks i will try that

Here is an example of campaign_lead_event_log structure but i can see any decisions inside

        "id": "41739",
        "event_id": "527",
        "lead_id": "8354",
        "campaign_id": "58",
        "rotation": "1",
        "date_triggered": "2025-02-28 08:09:05",
        "is_scheduled": "0",
        "system_triggered": "1",
        "metadata": "a:2:{s:6:\"failed\";i:1;s:6:\"reason\";s:50:\"Head Of Marketing Department has no email address.\";}",
        "channel": "email",
        "channel_id": "65",
        "non_action_path_taken": "0"
    }

That is an email send action

On the email stats i have this structure below Please can i know the campaign which have sent this emails? What is the use of “source_id”: “12” How is it linked? thanks for your reply

        "id": "33",
        "email_id": "9",
        "email_address": "pauleo@gmail.com",
        "date_sent": "2024-04-24 09:32:04",
        "is_read": "0",
        "is_failed": "0",
        "viewed_in_browser": "0",
        "tracking_hash": "6628d19445b9b600516137",
        "retry_count": "0",
        "source": "campaign.event",
        "source_id": "12",
        "open_count": "0",
        "open_details": "a:0:{}"
    },

My issue is the process of linking theme in a unique way