-
Notifications
You must be signed in to change notification settings - Fork 50
Add WooCommerce Tracks integration and the Onboarding funnel (4649) #3446
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: trunk
Are you sure you want to change the base?
Conversation
…ments into PCP-4649-track-wizard-screen-views
const updateFieldSources = ( currentSources, fieldName, source ) => { | ||
if ( ! source ) { | ||
return currentSources; | ||
} | ||
|
||
return { | ||
...currentSources, | ||
[ fieldName ]: { | ||
source, | ||
timestamp: Date.now(), | ||
}, | ||
}; | ||
}; | ||
|
||
const clearFieldSource = ( currentSources, fieldName ) => { | ||
const newSources = { ...currentSources }; | ||
delete newSources[ fieldName ]; | ||
return newSources; | ||
}; |
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'm uncertain if I like this direct integration into the reducer, as it implements tracking on this store only. This (a) does not scale well and (b) changes the responsibility of the store to handle two things at once
action.source | ||
); | ||
} | ||
|
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.
While working, this pattern is not ideal for several reasons:
- it adds bloat to the code and makes reducers look more complex than they are.
- I think tracking should not happen on reducer level, but on action level.
- It violates the single responsibility
My solution would be to create a new store for tracking with two actions: updateSources
and clearSources
. Then extend createHooksForStore() to dispatch the updateSources
action right after calling the original dispatcher, like this:
const setValue = useCallback(
(newValue, source = null) => { // ← add optional tracking argument here
actions[dispatcher](key, newValue);
if (source) { // ← dispatch conditional tracking here
const trackingActions = useDispatch('tracking-store');
trackingActions.updateSources(key, source);
}
},
[actions, key]
);
getFunnelsForStore, | ||
getTrackingStatus, | ||
} from './registry'; | ||
|
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.
With a dedicated Redux store for tracking
, this registry would become much simpler and reliable, as most of its logic would be part of the Redux store (a pattern that's more aligned with the code base)
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.
LGTM
Only one question to make sure there is no unintentional regression.
@@ -38,7 +38,7 @@ const StepProducts = () => { | |||
}; | |||
|
|||
initChoices(); | |||
}, [ canUseSubscriptions, optionState, products, setProducts ] ); | |||
}, [ canUseSubscriptions, isCasualSeller ] ); |
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 assume these dependencies were removed intentionally, and this is okay?
return false; | ||
} | ||
|
||
// Check store readiness. |
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 noticed a growing tendency to add more inline comments in the codebase. Personally, I believe inline comments are valuable when they clarify something non-obvious or explain edge cases, but in general, I prefer using them only when truly necessary.
Since some developers use them frequently and others rarely, it might be helpful to align on a shared approach to inline comments as a team. Perhaps we can discuss this outside of this PR to establish a consistent convention?
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 is a really great PR, thanks for the work on it @danieldudzic 🙌 I’ve also briefly tested it locally, and the code works fine for me.
One thing we might want to consider is what Philipp suggested: refactoring the tracking logic into a dedicated Redux store. But current PR looks good to me.
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.
LGTM except the above comments.
LGTM 👍 |
Description
This PR will introduce a tracking system for the onboarding flow with source-based field filtering, multi-funnel support, and extensible adapter architecture. The system prevents tracking loops and provides comprehensive analytics capabilities across the new Settings UI.
It monitors WordPress data stores rather than adding code to frontend components, ensuring comprehensive coverage of all state changes regardless of their source (user actions, API responses, system updates) while maintaining clean separation of concerns.
Core Components
1. Registry System (
registry.js
)2. Subscription Manager (
subscription-manager.js
)3. Source-Based Field Filtering (
utils.js
,subscription-manager.js
)Source tracking needs to be added because Redux store subscriptions and internal system updates create noise in analytics by triggering tracking events for non-user actions.
4. Adapter Pattern (
adapters/woocommerce-tracks.js
,adapters/console-logger.js
)5. Core Tracking Service (
services/funnel-tracking.js
)6. Funnel Configuration (
funnels/onboarding.js
)Implementation
setPersistent
/setTransient
actions'user'
,'system'
)Testing
Add to the browser console:
ppcp_onboarding_
prefixed events in console