-
Couldn't load subscription status.
- Fork 0
fix(SDK): Fix missing address on pageview and custom events #109
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
Conversation
|
bugbot run |
|
bugbot run |
|
bugbot run |
|
bugbot run |
|
bugbot run |
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.
Pull Request Overview
This PR fixes a bug where the address field was missing from pageview and custom events due to improper handling of undefined values in the event creation process. The solution introduces proper address validation and consistent null handling throughout the codebase.
- Fixes address assignment logic in
EventFactory.tsto properly handleundefinedandnullvalues - Adds comprehensive address validation utilities with trimming support
- Ensures consistent address handling across all event types and analytics methods
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/lib/event/EventFactory.ts |
Fixed address assignment logic in create and getEnrichedEvent methods to properly handle undefined values |
src/utils/address.ts |
Added new address validation utilities (isValidAddress, getValidAddress) with proper trimming |
src/FormoAnalytics.ts |
Updated all address handling to use new validation utilities for consistency |
test/lib/events.spec.ts |
Added basic tests for address assignment logic |
test/lib/event/EventFactory.spec.ts |
Added comprehensive tests for address validation and bug fix verification |
|
🎉 This PR is included in version 1.19.4 🎉 |
The Problem
The issue is in the
createmethod inEventFactory.ts. Look at this line:This line only sets the address if
formoEvent.addressis falsy. However, the problem is that for page events, thegeneratePageEventmethod creates apageEventobject that doesn't include an address field at all:When this gets passed to
getEnrichedEvent, theformoEvent.addressisundefined, notnull. ThegetEnrichedEventmethod then sets:So
commonEventData.addressbecomesundefined, and when the final check happens in thecreatemethod:The
!formoEvent.addresscheck fails becauseformoEvent.addressisundefined, and!undefinedistrue, but the address assignment doesn't work as expected.The Solution
The issue is that the address should be set in the
createmethod before callinggetEnrichedEvent, or the logic needs to be fixed to handleundefinedvalues properly.Let me fix this:
Now let me also check if there are any other places where this logic might need to be updated. Let me look at the
getEnrichedEventmethod to make sure it handles the address correctly:Perfect! Now let me run a quick test to make sure the changes work correctly. Let me check if there are any existing tests for this functionality:
Ran tool
Ran tool
Ran tool
Read file: test/lib/events.spec.ts
Let me create a simple test to verify that the fix works correctly:
Now let me run the tests to make sure our fix works:
The test is failing because it's trying to access
globalThis.location.hrefwhich doesn't exist in the test environment. Let me fix the test by mocking the global location:Now let me run the tests again:
I need to mock the document object as well. Let me fix the test:
Now let me run the tests again:
The navigator object is read-only. Let me create a simpler test that doesn't require mocking all the browser objects. Instead, let me create a unit test that focuses on the specific logic we fixed:
Now let me run the tests to make sure they pass:
Great! The tests pass. Now let me also run all tests to make sure I didn't break anything:
npm testPerfect! All tests are passing. Now let me create a simple test to verify that our fix works by creating a minimal test that doesn't require browser mocking:
Excellent! Now let me provide a summary of what I found and fixed:
Summary
I found and fixed the issue with the empty
addressfield in pageview and custom events. Here's what was happening:The Problem
generatePageEventmethod inEventFactory.tswas creating page events without anaddressfield:Inconsistent address handling: The
getEnrichedEventmethod was settingcommonEventData.addresstoundefinedwhenformoEvent.addresswas falsy, but the final check in thecreatemethod was using!formoEvent.addresswhich doesn't properly handleundefinedvalues.Logic flaw: The condition
!formoEvent.address && (formoEvent.address = address ? toChecksumAddress(address) : null)was not working correctly becauseformoEvent.addresswasundefined, and!undefinedistrue, but the assignment wasn't working as expected.The Fix
I made two key changes:
createmethod (src/lib/event/EventFactory.tsline ~520):getEnrichedEventmethod (src/lib/event/EventFactory.tsline ~225):Why This Fixes the Issue
createmethod now properly checks if the address isundefinedornulland sets it from the current address parameter.undefined, we now consistently usenullfor missing addresses.Result
Now when you have a connected wallet with address
0x1095bBe769fDab716A823d0f7149CAD713d20A13, all events (including page events) will include this address in theaddressfield instead of being empty.The fix ensures that:
nullinstead ofundefinedYour pageview and custom events should now properly include the current wallet address in the
addressfield!