Skip to content

[bug] analytics-aggregator: GlobalStats.total_campaigns never incremented — always returns 0 #720

Description

@gboigwe

Summary

The GlobalStats struct includes a total_campaigns: u64 field, initialized to 0 in initialize. None of record_impression, record_click, or record_conversion ever increment it. get_global_stats always returns total_campaigns = 0 regardless of how many campaigns have analytics data recorded.

Location

contracts/analytics-aggregator/src/lib.rs

pub struct GlobalStats {
    pub total_campaigns: u64, // always 0 — never incremented
    pub total_impressions: u64,
    pub total_clicks: u64,
    pub total_spend: i128,
    pub last_updated: u64,
}

Fix

Increment total_campaigns the first time analytics are recorded for a new campaign_id. Track seen campaigns using a SeenCampaign(u64) key, or increment on first record_impression when the campaign analytics record is newly created (i.e., total_impressions was 0 before):

if analytics.total_impressions == 1 { // first impression = first time seen
    global.total_campaigns += 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions