fix(analytics): correct per-campaign unique view counting#3024
Open
wucm667 wants to merge 1 commit intoknadh:masterfrom
Open
fix(analytics): correct per-campaign unique view counting#3024wucm667 wants to merge 1 commit intoknadh:masterfrom
wucm667 wants to merge 1 commit intoknadh:masterfrom
Conversation
When individual_tracking is enabled, DISTINCT ON(subscriber_id) deduplicated views globally across all campaigns, causing campaigns to be missing from multi-campaign analytics results if the same subscriber viewed more than one campaign. Change to DISTINCT ON(subscriber_id, campaign_id) to preserve one event per subscriber per campaign, which is the correct behavior for unique tracking. Fixes knadh#3023 Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3023
Bug
When
privacy.individual_trackingis enabled, requesting analytics formultiple campaigns at once via
/api/campaigns/analytics/views?id=X&id=Y&id=Zreturns incorrect results. Campaigns are missing from the response if the
same subscriber has viewed more than one of the queried campaigns.
Root Cause
The
get-campaign-analytics-unique-countsquery inqueries/campaigns.sqluses
DISTINCT ON(subscriber_id)which deduplicates across ALL campaignsglobally, instead of per-campaign. This means if subscriber A viewed both
campaign 1 and campaign 2, only the oldest event survives, and campaign 2
disappears from the results entirely.
Fix
Change
DISTINCT ON(subscriber_id)toDISTINCT ON(subscriber_id, campaign_id)and update
ORDER BYto includecampaign_id. This preserves one event persubscriber per campaign, which is the correct behavior for unique tracking.