Skip to content

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

Open
arman-uc wants to merge 1 commit into
LinkForty:mainfrom
arman-uc:fix/event-request-utc-and-omit-nulls
Open

arman-uc wants to merge 1 commit into
LinkForty:mainfrom
arman-uc:fix/event-request-utc-and-omit-nulls

Conversation

@arman-uc

Copy link
Copy Markdown

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)

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

1 participant