9 Commits

Author SHA1 Message Date
Jonas Bark
b666a8b637 Merge branch '6.4' into 6.5
Both branches implemented the install-referrer plan independently, so this
keeps 6.5's version of everything that overlapped and carries over only what
6.4 had on its own.

6.5's side won because it is genuinely further along:
- it uses play_install_referrer, where 6.4 used android_play_install_referrer,
  which pub.dev marks discontinued and explicitly replaced by it;
- it normalises the malformed-referrer error to FormatException instead of
  letting Uri.splitQueryString's ArgumentError escape, so the contract the
  plan documents actually holds;
- its startup guard also checks core.settings.isInitialized.

Carried over from 6.4 (Task 7, which 6.5 did not have): the campaign is now
pushed into RevenueCat as subscriber attributes on the reserved keys
($campaign, $mediaSource, $adGroup, $ad) plus bikecontrol_utm_medium. That is
what turns cost-per-install into trial-to-paid conversion and revenue per
campaign. It needs the raw referrer to outlive the one-shot Play read, so the
reporter also persists it under InstallReferrerReporter.referrerKey -- after a
successful send only, matching the existing done-flag.

campaign_attributes was rewritten onto 6.5's FormatException contract rather
than keeping 6.4's ArgumentError one.

Dropped android_play_install_referrer from pubspec, which the automatic merge
had left alongside play_install_referrer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 09:08:59 +02:00
Jonas Bark
0f5be96bcc feat(attribution): send the campaign to RevenueCat as subscriber attributes
setAttributes() already carried trainer, target, controllers, keymap and the
Supabase user id, but nothing about where the customer came from -- so revenue
could not be attributed to a campaign at all. This adds the Play install
referrer's UTMs on RevenueCat's reserved keys ($campaign, $mediaSource,
$adGroup, $ad) plus bikecontrol_utm_medium, which has no reserved equivalent.

That turns cost-per-install into trial-to-paid conversion and revenue per
campaign -- the difference between "the ads produce clicks" and "the ads
produce customers".

The reporter now persists the raw referrer, because the Play Install Referrer
API is readable only once and early, while RevenueCat attributes have to be
re-sent on every launch.

Corrects the parser's documented exception type while here: splitQueryString
raises ArgumentError on a bad percent escape, not FormatException.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 20:15:58 +02:00
Jonas Bark
186796f1a7 feat(attribution): report the Play install referrer once per install
The referrer source is behind an interface so the reporting logic is unit
tested without the Play plugin, which needs a real device.

The done-flag is only written after a successful send, so a failed report
retries on the next launch instead of vanishing. A missing referrer still
reports, because an install with no attribution is still an install and the
organic baseline is what paid gets compared against.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 20:13:16 +02:00
Jonas Bark
96198c2797 feat(attribution): parse UTMs from a Play install referrer
Pure function, no plugin dependency, so it is fully unit tested. Keeps Play's
organic referrer rather than discarding it -- that is how paid and organic
installs get told apart.

Lets FormatException escape on malformed encoding so the caller can record it
rather than silently losing an install.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 20:12:06 +02:00
Jonas Bark
351bb4ca63 fix(attribution): guard install-referrer report on settings init + document reporter ctor
Add core.settings.isInitialized to the Android install-referrer gate in
main.dart. Settings._prefs is a late SharedPreferences assigned during
Settings.init(); if SharedPreferences.getInstance() throws, _prefs is
never assigned. The referrer block previously read core.settings.prefs
unconditionally, so that failure would raise a LateInitializationError
from inside the guarded zone before runApp(BikeControlApp(error: error))
ran, skipping the intended error screen. Gating on isInitialized (already
used the same way in click_v2_onboarding.dart) skips the block instead.

Also add a one-line doc comment to the InstallReferrerReporter
constructor describing its injected source/prefs/send collaborators, to
match the class-level doc comment already present.

No logic changes in install_referrer_parser.dart.
2026-08-17 08:06:35 +02:00
Jonas Bark
d16f3b96e8 refactor(attribution): use maintained play_install_referrer plugin
android_play_install_referrer 0.4.0 is discontinued on pub.dev (replaced
by play_install_referrer). Swaps the reporter's PlayInstallReferrerSource
over to the maintained package; behaviour is unchanged — same read/catch/
recordError/return-null shape, just PlayInstallReferrer.installReferrer
instead of AndroidPlayInstallReferrer.installReferrer.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-17 07:57:10 +02:00
Jonas Bark
7e3a48d162 feat(attribution): report the Play install referrer once per install
The referrer source is behind an interface so the reporting logic is unit
tested without the Play plugin, which needs a real device.

The done-flag is only written after a successful send, so a failed report
retries on the next launch instead of vanishing. A missing referrer still
reports, because an install with no attribution is still an install and the
organic baseline is what paid gets compared against.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-16 20:29:42 +02:00
Jonas Bark
5d4a00e96a fix(attribution): normalise malformed-referrer errors to FormatException
Uri.splitQueryString throws ArgumentError, not FormatException, for
malformed percent-encoding (e.g. a truncated '%' or invalid escape) --
verified against the project's Dart SDK. The doc comment and Task 3's
brief both promise FormatException so callers can catch a single type
and route it through recordError. Catch the mismatch and rethrow as
FormatException; add a test proving the contract holds.
2026-08-16 20:26:46 +02:00
Jonas Bark
89f8638797 feat(attribution): parse UTMs from a Play install referrer
Pure function, no plugin dependency, so it is fully unit tested. Keeps Play's
organic referrer rather than discarding it -- that is how paid and organic
installs get told apart.

Lets FormatException escape on malformed encoding so the caller can record it
rather than silently losing an install.
2026-08-16 20:22:02 +02:00