Skip to content

fix(models): enforce UTC ISO 8601 timestamps and omit null attribution fields in EventRequest - #11

Merged
onamfc merged 1 commit into
LinkForty:mainfrom
arman-uc:fix/event-request-utc-and-omit-nulls
Oct 20, 2026
Merged

onamfc merged 1 commit into
LinkForty:mainfrom
arman-uc:fix/event-request-utc-and-omit-nulls

Conversation

@arman-uc

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #10

When tracking organic events (such as automatic screen tracking via LinkFortyNavigatorObserver or direct calls to LinkForty.trackEvent()), event requests to /api/sdk/v1/event fail with a 400 VALIDATION_ERROR on the server.

There were two causes in EventRequest:

  1. Timestamp wasn't UTC: DateTime.now() used local device time without the Z suffix. Strict backend validators (like Zod .datetime()) reject timestamps that don't end in Z.
  2. Null fields were sent in JSON: Unpopulated attribution fields (attributedLinkId, attributedClickId, linkOpenedAt, sessionId) were serialized as explicit null values instead of being left out. The backend validator expects optional strings and rejects null.

What changed?

  • Enforced UTC timestamps: Added .toUtc() in EventRequest's constructor so all timestamps are formatted in ISO 8601 UTC with a trailing Z (matching the pattern already used in attribution_context.dart).
  • Omitted null fields: Updated EventRequest.toJson() to remove keys with null values before sending, keeping the payload clean and organic events valid.
  • Added unit tests: Added tests in test/models/event_request_test.dart to verify UTC Z formatting, timezone conversion, and omission of null attribution fields.

How was it tested?

  • flutter test test/models/event_request_test.dart (all 7 tests passed)
  • flutter test (full suite of 118 tests passed)
  • flutter analyze (no issues found)

@onamfc

onamfc commented Oct 20, 2026

Copy link
Copy Markdown
Member

Thanks @arman-uc, this is a real bug and the fix is right. Converting to UTC matches attribution_context.dart, and dropping null keys matches what the event endpoint accepts. I verified it locally on current main: 129 tests pass, and flutter analyze and dart format are clean. CI is running now; once it's green we'll merge and publish it as 0.2.3. Sorry it sat for a month.

@onamfc
onamfc merged commit 8640a87 into LinkForty:main Oct 20, 2026
4 checks passed
@onamfc onamfc mentioned this pull request Oct 20, 2026
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.

Event tracking fails with 400 VALIDATION_ERROR on organic app opens

2 participants