Skip to content

Add trackConversion for sending conversion events#124

Open
randyriback wants to merge 3 commits into
mainfrom
rr-track-conversion
Open

Add trackConversion for sending conversion events#124
randyriback wants to merge 3 commits into
mainfrom
rr-track-conversion

Conversation

@randyriback
Copy link
Copy Markdown
Member

Summary

  • Adds ParselyTracker.trackConversion(url, conversionType, conversionLabel, ...) for firing conversion events (newsletter signups, subscriptions, purchases, link clicks, lead capture, custom). Internally constructs an event with action="conversion" and merges _conversion_type and _conversion_label into extra_data, which the Parse.ly conversions backend (conversions-realtime) extracts and uses as the goal identity.
  • New ConversionType enum mirrors the categories accepted server-side (newsletter_signup, lead_capture, link_click, subscription, purchase, custom).
  • Reuses the existing EventsBuilder / InMemoryBuffer / FlushQueue / ParselyAPIConnection pipeline — zero changes to the network layer, the buffer, or the flush manager.
  • Example app gains two sandbox buttons used during end-to-end verification.

This is the Android counterpart to the iOS SDK's trackConversion (parallel PR on AnalyticsSDK-iOS).

Test plan

Unit tests (all passing)

  • EventsBuilderTest.when building conversion event, then build the correct one — verifies the built event has action == "conversion", the right url and idsite, no pvid / vsid, and that _conversion_type / _conversion_label plus caller-supplied keys land in data.
  • ParselyTrackerTest.given tracker initialized, when calling trackConversion, do not throw any exception — smoke test for the public entry point (mirrors the existing call-doesn't-throw tests for other tracking methods).

Full suite (./gradlew :parsely:testDebugUnitTest): EventsBuilderTest 11 tests / ParselyTrackerTest 5 tests / 0 failures.

Manual end-to-end (Android emulator: Pixel 5, android-34, default arm64-v8a)

  • Built and installed the example app on the emulator.
  • Flipped dryRun to false temporarily in MainActivity.java to exercise the real network path.
  • Tapped Track Pageview (sandbox) and Track Conversion (sandbox) against the sandbox.joshhanson.io apikey.
  • Verified the on-wire JSON via adb logcat Parsely:V '*:S':
    {
      "action": "conversion",
      "url": "https://sandbox.joshhanson.io/path/test-conversion2",
      "idsite": "sandbox.joshhanson.io",
      "data": {
        "_conversion_type": "subscription",
        "_conversion_label": "android_sdk_smoke_test",
        "plan": "weekly",
        "source": "android_demo_app",
        "os": "android",
        "os_version": "34",
        "parsely_site_uuid": "...",
        "ts": 1778782087996
      }
    }

Testing Screenshots

Xnip2026-05-14_20-27-24 Screenshot 2026-05-14 at 8 46 39 PM

randyriback and others added 2 commits May 14, 2026 20:38
Exposes a new public method on ParselyTracker for firing conversion
events (newsletter signups, subscriptions, purchases, link clicks,
lead capture, and arbitrary custom conversions) using the existing
event queue, flush, and mobileproxy pipeline.

- New ConversionType enum mirrors the categories accepted by the
  Parse.ly conversions backend (NEWSLETTER_SIGNUP, LEAD_CAPTURE,
  LINK_CLICK, SUBSCRIPTION, PURCHASE, CUSTOM). Each case carries the
  wire-format string the backend expects in `_conversion_type`.
- trackConversion(url, conversionType, conversionLabel, ...) merges
  `_conversion_type` and `_conversion_label` into the event's
  extra_data alongside caller-supplied keys. Reserved keys cannot be
  overridden by caller extraData (caller values are applied first,
  reserved keys last).
- The event is dispatched through the existing EventsBuilder /
  enqueueEvent / FlushQueue / mobileproxy pipeline. No changes to
  EventsBuilder, the buffer, the flush manager, or the API connection.
- Tests: EventsBuilderTest gains "when building conversion event,
  then build the correct one" covering the conversion event shape
  (action, idsite, url, merged extra_data, absence of pvid/vsid).
  ParselyTrackerTest gains a smoke test that the public entry point
  doesn't throw when called after init.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds two buttons on the main screen — "Track Pageview (sandbox)" and
"Track Conversion (sandbox)" — that fire against the
`sandbox.joshhanson.io` apikey on a shared test URL. The pageview lets
a session accrue history before the conversion fires so the conversions
topology has something to attribute to.

NOTE: the example app initializes the SDK with `dryRun=true`, which
suppresses real network sends. To exercise these buttons end-to-end
against mobileproxy, temporarily flip the fourth argument of
`ParselyTracker.init(...)` to `false`.

Used during the manual end-to-end verification of trackConversion on
the Android emulator: with logcat filtered to `Parsely:V`, confirm the
emitted "POST Data {...}" JSON includes `action: "conversion"` and the
`_conversion_type` / `_conversion_label` keys, then watch
dash.parsely.com for the conversion in the conversions report.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@randyriback randyriback requested a review from wzieba May 15, 2026 08:34
The binary-compatibility-validator plugin tracks the SDK's public API
surface in parsely.api. Adding ConversionType + trackConversion to the
public interface requires regenerating the snapshot via ./gradlew apiDump.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 88.46154% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.46%. Comparing base (6c22480) to head (0025deb).

Files with missing lines Patch % Lines
...m/parsely/parselyandroid/ParselyTrackerInternal.kt 78.57% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #124      +/-   ##
==========================================
+ Coverage   71.32%   73.46%   +2.14%     
==========================================
  Files          22       23       +1     
  Lines         415      441      +26     
  Branches       50       52       +2     
==========================================
+ Hits          296      324      +28     
+ Misses        105       99       -6     
- Partials       14       18       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant