Skip to content

feat: add Pinterest click ID capture (epik/_epik)#1265

Open
jciafardone wants to merge 25 commits into
mParticle:developmentfrom
jciafardone:feat/pinterest-click-id-capture
Open

feat: add Pinterest click ID capture (epik/_epik)#1265
jciafardone wants to merge 25 commits into
mParticle:developmentfrom
jciafardone:feat/pinterest-click-id-capture

Conversation

@jciafardone
Copy link
Copy Markdown

Background

  • Pinterest surfaces click identifiers as the epik query parameter and/or the epik / _epik cookie (and similar storage). Those values are used with Pinterest Conversions API / tag flows.
  • The Web SDK’s Integration Capture path already maps other partners’ IDs from URL, cookies, and localStorage into custom flags and related outputs. Pinterest was not represented in that mapping, so those IDs were not captured consistently for downstream event payloads.
  • epik and _epik both correspond to the same logical Pinterest click id; they must map to a single custom flag without letting lower-priority sources override a URL value in ambiguous cases.

What Has Changed

  • src/integrationCapture.ts
    • Added epik and _epik to integrationMappingExternal, both mapped to custom flag Pinterest.click_id, with references to Pinterest developer and help documentation where appropriate.
    • Added Pinterest deduplication in capture(): when a Pinterest id appears in the query string, Pinterest keys are dropped from cookies and localStorage before merge; when there is no query Pinterest id but one exists in localStorage, Pinterest keys are dropped from cookies—aligned with existing Facebook (fbclid / _fbc) and Rokt precedence patterns.
    • Kept _scid / SnapchatConversions.Cookie1 as a sibling mapping (no nesting under Pinterest keys).
  • Tests
    • test/jest/integration-capture.spec.ts: coverage for Pinterest from query, cookie, and localStorage; precedence cases; custom flags; constructor keys; refactors to reduce duplication and keep Sonar duplication down where practical.
    • test/src/tests-integration-capture.ts: Karma-style coverage for captured custom flags including Pinterest alongside existing integrations (e.g. Snap), using shared expectations/helpers where the file already does so.
  • Housekeeping
    • Test files use window for DOM globals where needed so the distribution build (Rollup + TypeScript) stays compatible with Window augmentation for mParticle.

Screenshots/Video

  • Not applicable (SDK / unit + integration test changes only; no UI).

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation. (SDK mapping is self-documented via comments + links in code; say if you also updated public docs elsewhere.)
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • Supersedes the earlier PR that closed when the head branch was renamed from patch-1 to feat/pinterest-click-id-capture for the semantic branch name check.
  • Fork PR caveat: BrowserStack and Google Chat notification jobs may still fail on fork PRs when upstream secrets are not available to the workflow; core build, lint, and Jest runs are the reliable signal for contributors.

Reference Issue (For employees only. Ignore if you are an outside contributor)

  • N/A — outside contributor; no internal go/j ticket.

jciafardone and others added 25 commits December 5, 2025 17:34
Add Pinterest _epik parameter mapping to integrationMappingExternal.

- Maps _epik to Pinterest.click_id custom flag
- Supports capture from URL query params, cookies, and localStorage
- Follows standard priority: query params > localStorage > cookies
- Outputs to CUSTOM_FLAGS (same as other click ID integrations)

Reference: https://help.pinterest.com/en/business/article/add-event-codes

Testing:
- Verified extraction from URL, cookie, and localStorage sources
- Confirmed priority resolution works correctly
- Validated custom flag mapping to Pinterest.click_id
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
- Add epik parameter mapping in addition to _epik
- Both epik and _epik map to Pinterest.click_id custom flag
- Support capture from query params, cookies, and localStorage
- Add comprehensive tests for both parameter variants
- Reference: https://developers.pinterest.com/docs/track-conversions/track-conversions-in-the-api/
added output for _epik
Co-authored-by: Robert Ing <rmi22186@gmail.com>
Stub epik in getQueryParams and expect Pinterest.click_id on events,
matching the Snap integration test pattern.
Extract expectCapturedSnapchatAndPinterestFlags helper to satisfy
duplication threshold on new code.
- Add expectCapturedGoogleFacebookFlags helper
- Remove duplicate commerce it blocks (identical copies)
- expectStubbedIntegrationCaptureFlags wraps Google/Facebook + Snap/Pinterest
- Shared commerce purchase helpers and constants
- logThreeEventsUploadAndParseBatch for batch upload tests
Replace duplicated event/pageview and commerce it() bodies with
CAPTURE_CUSTOM_FLAG_CASES and COMMERCE_CAPTURE_CASES tables.
…stomFlags block

- Fix indentation and close describe before partner identities suite
- Use stable assertions (toBeDefined + includes) per review
Sonar rule javascript:S7764 prefers globalThis over window in tests; behavior unchanged under jsdom.
Satisfies Sonar no-zero-fraction rule; value unchanged.
A missing brace nested _scid under _epik and broke integrationMappingExternal parsing. Restore _scid as a top-level key next to Pinterest entries.
Assert both Pinterest source keys are registered in filtered mappings, then that Pinterest.click_id is one of the input values (same key, last-write wins).
epik and _epik map to the same custom flag. Prefer query params over localStorage and cookies, then localStorage over cookies, mirroring Facebook fbclid/_fbc and Rokt-style precedence. Add Jest coverage for each tier.
Add clickIdsAfterFullCaptureAllMode helper; drive Pinterest, Snapchat, and Rokt #capture cases from tables; consolidate capture V2 mode gating tests.
… tests

Restores Window augmentation typing for mParticle (fixes rollup TS2352). Sonar may flag window again; acceptable tradeoff.
@jciafardone jciafardone requested a review from a team as a code owner May 14, 2026 20:08
@cursor
Copy link
Copy Markdown

cursor Bot commented May 14, 2026

PR Summary

Medium Risk
Changes click-ID capture/merge precedence and adds new Pinterest identifiers, which can alter custom flags sent with events and batches. Logic is localized and covered by new unit/integration tests, keeping overall risk moderate.

Overview
Adds Pinterest click-ID support by capturing epik and _epik from query params, cookies, and localStorage, mapping both to the Pinterest.click_id custom flag.

Updates IntegrationCapture.capture() merge precedence so Pinterest query params win over storage/cookies (and localStorage wins over cookies when no query param is present), and expands/refactors Jest + browser integration tests to cover Pinterest capture and precedence alongside existing partners.

Reviewed by Cursor Bugbot for commit c5abf7d. Bugbot is set up for automated code reviews on this repo. Configure here.

@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant