Skip to content

feat(purchases): Add setPostHogUserId() method to Purchases API#2495

Merged
tonidero merged 2 commits into
mainfrom
origin/implement-setposthoguserid
Jul 9, 2025
Merged

feat(purchases): Add setPostHogUserId() method to Purchases API#2495
tonidero merged 2 commits into
mainfrom
origin/implement-setposthoguserid

Conversation

@hussain-mustafa990

@hussain-mustafa990 hussain-mustafa990 commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

Checklist

  • If applicable, unit tests
  • If applicable, create follow-up issues for purchases-ios and hybrids

Motivation

Add a dedicated setPostHogUserId method to the SDK which was currently missing.

Changes Made:

  1. Added PostHog User ID to Reserved Subscriber Attributes

    • Added POSTHOG_USER_ID("\$posthogUserId") to ReservedSubscriberAttribute enum
    • Added PostHogUserId object to SubscriberAttributeKey.IntegrationIds sealed class
  2. Implemented Public API Method

    • Added setPostHogUserId(postHogUserId: String?) method to Purchases class
    • Added comprehensive KDoc documentation explaining the method's purpose and parameters
  3. Added Orchestrator Implementation

    • Implemented setPostHogUserId() method in PurchasesOrchestrator
    • Added debug logging for method calls
    • Uses setAttribute() instead of setAttributionID() since PostHog is an analytics platform, not an attribution platform
  4. Added Integration Tests

    • Added test case setPostHogUserId() in SubscriberAttributesPurchasesTests
    • Uses integrationIDTest() helper method following the established pattern
    • Verifies correct attribute key and value are passed to subscriber attributes manager
  5. Updated API Documentation

    • Added method signature to purchases/api-defauts.txt
    • Ensures API documentation is up to date

Usage Example:

// Set PostHog user ID for current user
Purchases.sharedInstance.setPostHogUserId("user123")

Note: This is my first ever commit to the codebase besides documentation, hopefully I did everything as expected. Let me know if I have to make any adjustments.

@hussain-mustafa990 hussain-mustafa990 added the pr:feat A new feature label Jul 8, 2025
@hussain-mustafa990 hussain-mustafa990 removed the pr:feat A new feature label Jul 9, 2025
@tonidero tonidero added the pr:feat A new feature label Jul 9, 2025
@codecov

codecov Bot commented Jul 9, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.35%. Comparing base (7414e17) to head (ba3159c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2495      +/-   ##
==========================================
+ Coverage   78.33%   78.35%   +0.01%     
==========================================
  Files         286      286              
  Lines       10432    10439       +7     
  Branches     1500     1500              
==========================================
+ Hits         8172     8179       +7     
  Misses       1614     1614              
  Partials      646      646              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tonidero tonidero left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!! This looks great! 🙌

@tonidero tonidero added this pull request to the merge queue Jul 9, 2025
Merged via the queue into main with commit ec097c2 Jul 9, 2025
14 checks passed
@tonidero tonidero deleted the origin/implement-setposthoguserid branch July 9, 2025 13:32
github-merge-queue Bot pushed a commit that referenced this pull request Jul 9, 2025
**This is an automatic release.**

## RevenueCat SDK
### ✨ New Features
* feat(purchases): Add setPostHogUserId() method to Purchases API
(#2495) via Hussain Mustafa (@hussain-mustafa990)
### 🐞 Bugfixes
* Improves button progress indicator size calculation. (#2485) via
JayShortway (@JayShortway)

### 🔄 Other Changes
* Revert "BC8 migration (#2477)" (#2501) via Toni Rico (@tonidero)
* Add codelab instructions on README file (#2489) via Jaewoong Eum
(@skydoves)
* Use collectAsStateWithLifecycle instead of collectAsState in Compose
(#2488) via Jaewoong Eum (@skydoves)
* Improve Composable stabilities (#2478) via Jaewoong Eum (@skydoves)
* [AUTOMATIC][Paywalls V2] Updates paywall-preview-resources submodule
(#2486) via RevenueCat Git Bot (@RCGitBot)
* BC8 migration (#2477) via Toni Rico (@tonidero)
* Fixes building sample apps with SNAPSHOT dependencies (#2483) via
JayShortway (@JayShortway)
* [AUTOMATIC][Paywalls V2] Updates paywall-preview-resources submodule
(#2484) via RevenueCat Git Bot (@RCGitBot)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:feat A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants