Skip to content

Add event deduplication via optional id parameter#136

Merged
hownowstephen merged 4 commits into
mainfrom
MESS-678_add-event-dedup-id
May 8, 2026
Merged

Add event deduplication via optional id parameter#136
hownowstephen merged 4 commits into
mainfrom
MESS-678_add-event-dedup-id

Conversation

@hownowstephen
Copy link
Copy Markdown
Contributor

@hownowstephen hownowstephen commented May 7, 2026

Summary

  • Add optional id: and timestamp: keyword arguments to track and track_anonymous for event deduplication and explicit timestamp control
  • The id should be a ULID — no client-side validation, API rejects invalid values
  • Matches the Go client's WithEventID() pattern

Fixes #107. Replaces #108 and #85.

⚠️ Breaking change

Adding keyword arguments to track and track_anonymous means callers using implicit hash syntax must add explicit braces:

# Before (no longer works — Ruby interprets bare key:value as keyword args)
client.track(5, "purchase", type: "socks", price: "13.99")

# After
client.track(5, "purchase", { type: "socks", price: "13.99" })

This is a semver-major change. All README examples updated.

Docs team: The Track API reference Ruby tab and any other docs showing track()/track_anonymous() Ruby examples should be checked for implicit hash syntax.

Test plan

  • CI passes on Ruby 3.3, 3.4, 4.0, head
  • id field present in request body when provided
  • id field absent when not provided
  • timestamp keyword arg sets top-level timestamp
  • timestamp in attributes hash still works (backwards compat for that path)
  • Invalid timestamps (milliseconds, strings, dates) omitted from body

Add optional `id:` keyword argument to `track` and `track_anonymous`
for event deduplication. The id should be a ULID. No client-side
validation — the API rejects invalid values.

Fixes #107
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b930f2a. Configure here.

Comment thread lib/customerio/client.rb Outdated
Allow passing timestamp: as a keyword arg to track and track_anonymous,
alongside the existing id: keyword. The explicit keyword takes
precedence over a timestamp in the attributes hash. Backwards
compatible — existing callers that pass timestamp in attributes
continue to work.
track() and track_anonymous() now accept id: and timestamp: keyword
args. Callers must wrap attributes in explicit braces to avoid Ruby 3.x
keyword argument ambiguity.

Update all spec calls and README examples to use explicit hash syntax.
WebMock compares serialized JSON strings, so key order must match
the insertion order in create_event (timestamp before id).

Disable Metrics/ParameterLists on create_event — private method
with keyword args, splitting would add complexity for no benefit.
@hownowstephen hownowstephen merged commit 6d08ff2 into main May 8, 2026
9 checks passed
@hownowstephen hownowstephen deleted the MESS-678_add-event-dedup-id branch May 8, 2026 14:27
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.

[Feature Request] Add support for deduplicating events with event IDs

2 participants