feat(topsort): support offsite click and impression tracking#3830
feat(topsort): support offsite click and impression tracking#3830barbmarcio wants to merge 3 commits into
Conversation
Make resolvedBidId optional and add a dsp_metadata field to the Topsort click and impression actions so offsite (and organic) events can be sent via Segment. Previously resolvedBidId was required by the destination's payload validation, which rejected offsite events that legitimately have no resolved bid, and there was no mapping for dsp_metadata at all.
…trings Address PR review: rename the dsp_metadata mapping field to dspMetadata (camelCase, matching codebase convention) while still sending dsp_metadata in the API payload. Add NormalizeDspMetadata to coerce non-string values to strings, since the Report Events API expects a map of string to string and a single non-string value would otherwise 422 the whole batch.
|
Hi @barbmarcio thanks for the PR. Functionally it looks fine to me. Can you add some proof of testing? you can run the local testing tool using this command:
You can then use the UI in the browser to send some test events. Or you can use postman. One more thing - do you work for Topsort? Can you send me an email to jayoub@twilio.com please? I can't accept a PR from someone who is not from Topsort, or without having someone from Topsort approve the PR. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Enables Topsort click/impression actions to accept offsite/organic events by making resolvedBidId optional and adds forwarding of DSP click identifiers via dsp_metadata.
Changes:
- Make
resolvedBidIdoptional for click and impression actions to unblock offsite/organic events. - Add
dspMetadatainput field and transform it todsp_metadatawith string coercion before sending to Topsort. - Update tests and snapshots to cover offsite events and DSP metadata coercion.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/destination-actions/src/destinations/topsort/pageviews/tests/snapshots/snapshot.test.ts.snap | Snapshot update to reflect dsp_metadata output shape. |
| packages/destination-actions/src/destinations/topsort/impression/index.ts | Makes resolvedBidId optional; adds dspMetadata mapping and normalizes into dsp_metadata. |
| packages/destination-actions/src/destinations/topsort/impression/generated-types.ts | Updates payload types for optional resolvedBidId and new dspMetadata. |
| packages/destination-actions/src/destinations/topsort/impression/tests/index.test.ts | Adds test coverage for offsite impressions and dspMetadata coercion behavior. |
| packages/destination-actions/src/destinations/topsort/impression/tests/snapshots/snapshot.test.ts.snap | Snapshot update to include dsp_metadata. |
| packages/destination-actions/src/destinations/topsort/functions.ts | Adds NormalizeDspMetadata helper for string coercion. |
| packages/destination-actions/src/destinations/topsort/click/index.ts | Makes resolvedBidId optional; adds dspMetadata mapping and normalizes into dsp_metadata. |
| packages/destination-actions/src/destinations/topsort/click/generated-types.ts | Updates payload types for optional resolvedBidId and new dspMetadata. |
| packages/destination-actions/src/destinations/topsort/click/tests/index.test.ts | Adds test coverage for offsite clicks and dspMetadata coercion behavior. |
| packages/destination-actions/src/destinations/topsort/click/tests/snapshots/snapshot.test.ts.snap | Snapshot update to include dsp_metadata. |
Summary
Offsite (and organic) click and impression events could not be sent to Topsort through the Segment integration. The destination's
clickandimpressionactions markedresolvedBidIdas a required field, so Segment's payload validation rejected any event without one — returning400: The root value is missing the required field 'resolvedBidId'— even though the Topsort/v2/eventsAPI itself accepts offsite events with no resolved bid (they're attributed viaentity,externalCampaignId/externalVendorIdandchannel: "offsite").On top of that, there was no mapping for
dsp_metadataanywhere in the actions, so customers had no way to forward the DSP click identifiers (e.g.gclidfor Google, or the Meta equivalent) that Topsort needs to send offsite conversions back to Google/Meta for optimization.Changes
resolvedBidIdoptional (required: false) on theclickandimpressionactions. Onsite sponsored events continue to send it exactly as before; offsite/organic events can now omit it.dsp_metadataobject field (mapped from$.properties.dsp_metadata) to theclickandimpressionactions. It's free-form because the accepted keys vary per advertising platform.resolvedBidId, withdsp_metadata) and regenerated types and snapshots.This is a non-breaking change — it only loosens an existing constraint and adds a new optional field. No existing onsite mappings are affected.
Testing
yarn cloud jest --testPathPattern="topsort"— all 10 suites pass (32 tests).