fix(report-summary): multiply Developer Proceeds by Units in sales summary#5
Open
gonzalobandeira wants to merge 1 commit into
Open
Conversation
…mary Apple's SALES report `Developer Proceeds` column is the per-unit amount, not the row total. Each TSV row represents `Units` sales at `Developer Proceeds` each, so the row's contribution to total proceeds is Units × Developer Proceeds. The previous implementation summed the column value directly, ignoring Units, which undercounted any row with Units > 1. The undercount factor equals the average Units-per-row for the dataset — typically 5-10x on monthly reports for actively-selling apps. Same fix applied to subscriberSummary for symmetry, though SUBSCRIBER rows are per-transaction so Units is usually 1. Tests updated: - salesSummary_proceedsByCurrency: previously asserted the buggy values (sum of per-unit prices) — now asserts Units × proceeds. - Added salesSummary_proceedsScalesWithUnits as a regression test with a single Units=100 row. - Added salesSummary_perAppProceedsScalesWithUnits for the per-app accumulator path.
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.
Summary
Fixes a bug in
ReportSummary.salesSummary(and the symmetric path insubscriberSummary) whereDeveloper Proceedswas summed without multiplying byUnits, causing total proceeds to be undercounted by a factor equal to the average Units-per-row.The bug
Apple's SALES report aggregates transactions by
[Country Code, Product Type, Customer Price, ...], producing rows like:Developer Proceedsis the per-unit amount the developer receives. The row's contribution to total proceeds isUnits × Developer Proceeds, notDeveloper Proceedsalone.The current code on
develop(ReportSummary.swift:52and:68):Impact
Real-world example from an app with ~$650 in monthly proceeds:
About 5.7× undercount. The factor depends on the average Units-per-row in the dataset, which is roughly proportional to a row's homogeneity — e.g. a single price tier in one country with many sales will have very high Units, magnifying the undercount.
The bug is not visible to anyone who only looks at
total_units,by_product_type, ortop_countries(those useunitscorrectly). It only affectsproceeds_by_currency(both top-level and inside eachby_appentry).The fix
In
salesSummary:Same treatment applied to the per-app accumulator (
appStats[...].proceedsByCurrency) and tosubscriberSummaryfor symmetry (SUBSCRIBER rows are typicallyUnits=1, so this is mostly defensive).financialSummaryis not affected — it usesPartner Share, which Apple already provides as the row total.Tests
salesSummary_proceedsByCurrency: previously asserted the buggy values (it summed per-unit amounts, which made the test pass even though the production behaviour was wrong). Updated to assertUnits × Developer Proceeds.salesSummary_proceedsScalesWithUnits: regression test with a singleUnits=100row that would catch any reintroduction of the bug.salesSummary_perAppProceedsScalesWithUnits: same regression for theby_apppath.All 24 tests in
ReportSummary Testspass on this branch (swift test --filter ReportSummaryTests).How to verify against real data
After applying this fix and calling
analytics_sales_reportwithsummary_only: true, theproceeds_by_currencyshould now match what you get by manually computingsum(Units × Developer Proceeds) per currencyfrom the raw rows (which is also what App Store Connect's "Sales and Trends" dashboard displays in your home currency, modulo FX).