Skip to content

Tercept Analytics Adapter: single request per auction, concurrent auction isolation & payload optimisation#14679

Open
mdusmanalvi wants to merge 7 commits intoprebid:masterfrom
mdusmanalvi:tercept-analytics-refactor
Open

Tercept Analytics Adapter: single request per auction, concurrent auction isolation & payload optimisation#14679
mdusmanalvi wants to merge 7 commits intoprebid:masterfrom
mdusmanalvi:tercept-analytics-refactor

Conversation

@mdusmanalvi
Copy link
Copy Markdown
Contributor

@mdusmanalvi mdusmanalvi commented Apr 3, 2026

Type of change

  • Bugfix
  • Feature
  • New bidder adapter
  • Updated bidder adapter
  • Updated analytics adapter
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Does this change affect user-facing APIs or examples documented on http://prebid.org?
  • Other

Description of change

Refactored the Tercept Analytics Adapter to fix a data-loss bug with concurrent auctions, reduce request volume from ~4 per auction to 1, and trim payload size.

  1. Concurrent auction isolation (bug fix):

    • Replaced shared events object with a Map keyed by auctionId
    • Previously, a new AUCTION_INIT would reset shared state, silently dropping data from any in-flight auction; each auction is now fully isolated
  2. Single request per auction:

    • All bid events (BID_WON, AD_RENDER_SUCCEEDED, AD_RENDER_FAILED, BIDDER_ERROR) are now accumulated into the bids array and flushed in one POST ~1.5s after AUCTION_END
    • Reduces requests from ~4 per auction to 1, eliminating the need to join separate payloads server-side
  3. Page-exit reliability via sendBeacon:

    • visibilitychange handler flushes pending auctions using navigator.sendBeacon instead of ajax, guaranteeing delivery when the user navigates away before the 1.5s timer fires
  4. Payload size reduction:

    • Removed ad (full creative markup, 10–50 KB per bid), native payload, and adUrl from bid objects
    • auctionInit.bidderRequests trimmed to first entry only — device and site data is identical across all bidder requests
  5. Resilience and cleanup:

    • Added try/catch around track() so any unexpected error does not disrupt the publisher page
    • Implemented disableAnalytics to cancel pending timers and clear maps on teardown, preventing state leaking across SPA navigations

- Replace shared events object with per-auctionId Map to fix data loss
  when multiple auctions run concurrently
- Accumulate BID_WON, AD_RENDER_SUCCEEDED, AD_RENDER_FAILED and
  BIDDER_ERROR into the bids array; flush once 1.5s after AUCTION_END
- Use navigator.sendBeacon on visibilitychange so data survives page exit
- Add disableAnalytics to clear pending timers and maps on teardown
- Add try/catch around track() to prevent adapter errors disrupting page
- Remove ad, native and adUrl fields from bid payloads to reduce size
- Limit auctionInit.bidderRequests to first entry (device/site data
  is identical across all bidder requests)
- Add is_pl flag (true on first bid of first auction per page load)
Replace tests that assumed multiple requests per auction and separate
top-level keys (bidWon, adRenderSucceeded, etc.) with tests matching
the new single-request-per-auction design. Covers:

- Request timing: no send before 1.5s timer, one request per auction
- Payload structure: top-level shape, bidderRequests trimmed to first,
  host/path/search attached at send time, ad/native/adUrl absent
- All event handlers: BID_REQUESTED, BID_RESPONSE, BID_TIMEOUT, NO_BID,
  BID_WON, AD_RENDER_SUCCEEDED, AD_RENDER_FAILED, BIDDER_ERROR
- is_pl flag: true on first bid of first auction only, reset on disable
- Concurrent auction isolation: separate bids and auctionInit per id
- visibilitychange flush via sendBeacon
- disableAnalytics: cancels timers, clears maps, resets firstSent
- Error resilience: unknown auctionIds and undefined args do not throw
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Tread carefully! This PR adds 81 linter errors (possibly disabled through directives):

  • modules/terceptAnalyticsAdapter.js (+81 errors)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a55a159699

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 3, 2026

Coverage Report for CI Build 24229648318

Coverage increased (+0.003%) to 96.347%

Details

  • Coverage increased (+0.003%) from the base build.
  • Patch coverage: 387 of 387 lines across 2 files are fully covered (100%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
libraries/medianetUtils/logger.js 2 83.78%

Coverage Stats

Coverage Status
Relevant Lines: 225213
Covered Lines: 216986
Line Coverage: 96.35%
Relevant Branches: 52473
Covered Branches: 42617
Branch Coverage: 81.22%
Branches in Coverage %: No
Coverage Strength: 71.23 hits per line

💛 - Coveralls

mdusmanalvi and others added 3 commits April 3, 2026 11:27
…mport

- Fix 81 indent errors by properly indenting the try block body
- Replace window.addEventListener with document.addEventListener for
  visibilitychange — the event is non-bubbling and fires on document,
  so window never received it in Firefox/Safari
- Replace navigator.sendBeacon with the ajax.js sendBeacon wrapper
  as required by Prebid.js linting rules
- Update test to stub ajax.sendBeacon and dispatch event on document
Split multi-property spread objects onto separate lines to satisfy
the @stylistic/object-property-newline ESLint rule.
@mdusmanalvi
Copy link
Copy Markdown
Contributor Author

@jefftmahoney Had already resolved the codex review comments. Would it be possible to perhaps expedite the review?

@mdusmanalvi
Copy link
Copy Markdown
Contributor Author

@patmmccann was really hoping this could be part of the next release, would it be possible to have this reviewed sooner?

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.

2 participants