-
Notifications
You must be signed in to change notification settings - Fork 2
feat(prebid): add Prebid.js analytics integration addon #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Add OptablePrebidAnalytics class to track auction and bid events from Prebid.js and send them to Optable's witness API. The addon supports configurable sampling rates, debug logging, and custom analytics data injection. Key features: - Tracks auctionEnd and bidWon events with detailed bid request/response data - Extracts and reports Optable EID matchers and sources from ORTB2 data - Implements deterministic and random sampling strategies - Handles missed events by processing Prebid's event history The witness API type definition is updated to support nested objects and arrays in event properties to accommodate complex auction data structures.
Add new fields to improve analytics tracking and debugging: - Replace 'missed' with 'optableLoaded' for clearer semantics - Rename 'hasOptable' to 'optableTargetingDone' for consistency - Include 'optableSampling' rate in witness payload - Add 'userAgent' to payload for better debugging - Expose 'optableTargetingDone' at bidder request level
jrosendahl-opt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions about sampling and handling auctions with no bid won events.
If i missed where this is happening, please feel free to explain.
| } | ||
|
|
||
| // Random sampling | ||
| return Math.random() < this.config.samplingRate!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the sample rate by default is on a per auction basis. Preferably we want to sample per session, we should be able to use a session cookie to manage sampling rate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added additional parameter to the config that allow sample per session, but I've kept per-event sampling as default option as it will provide more visibility. But both variants are configurable and can be set for each bundle individually.
|
|
||
| // Store the processed auction | ||
| this.auctions.set(auctionId, { auctionEnd: event, createdAt: new Date(), missed }); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not seeing where we are sending auction data in cases where no bid won event occurs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added extra processing. Default timeout for bidWon event 10s. Configurable.
Introduce `bidWinTimeout` to track bid win events. If a bid win is not received within the configured timeout after an auction ends, a witness event is sent with `bidWon: null` to indicate a missed bid. Add `samplingVolume` configuration, allowing analytics sampling to be applied either per `event` (default) or per `session`. Session-based sampling ensures a consistent sampling decision for a user throughout their browsing session. The analytics payload is enhanced with `auctionEndAt`, `bidWonAt`, and `optableLoaded` fields, and the `bidWon` object can now be `null` to explicitly represent cases where no bid was won or tracked. Update `witness.ts` to allow `null` values in the witness payload properties. Refactor `analytics.test.ts` to simplify `eids` structure and remove redundant fields.
932ed9e to
adfc6c3
Compare
Clears the `auctionEndTimeoutId` when a bid is won to prevent it from firing after the auction is complete. Additionally, removes the auction object from the internal map to prevent memory leaks and ensure proper resource cleanup.
Yoshiji
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM. Thank you for the test coverage 👍
|
|
||
| declare global { | ||
| interface Window { | ||
| // @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand there is not much value in typing the window object, however should we add
OptablePrebidAnalytics["constructor"] to OptableGlobal for completion or just get rid of OptableGlobal type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Moves device object assignment to a higher scope for consistent use across the analytics payload. Removes the redundant `userAgentRaw` field, as the parsed `userAgent` is already available.
domngco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add OptablePrebidAnalytics class to track auction and bid events from Prebid.js and send them to Optable's witness API. The addon supports configurable sampling rates, debug logging, and custom analytics data injection.
Key features:
The witness API type definition is updated to support nested objects and arrays in event properties to accommodate complex auction data structures.