-
Notifications
You must be signed in to change notification settings - Fork 23
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
fix(subscribe): optionally include metadata on subscribe #1763
Conversation
* | ||
* @return array|WP_Error|true Contact data if it was added, or error otherwise. True if async. | ||
*/ | ||
public static function subscribe( $contact, $lists = false, $async = false, $context = 'Subscribe contact' ) { | ||
public static function subscribe( $contact, $lists = false, $async = false, $context = 'Subscribe contact', $include_metadata = false ) { |
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.
Do you remember which case we were handling when we decided to remove the metadata from here?
If we are setting this param to true
everywhere we call this method there will likely be a regression... or is there anywhere this will still be called as false
?
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 think we were accounting for when the reader updates their newsletter subscriptions via the My Account > Newsletters UI. In that scenario, we shouldn't be sending any additional metadata as part of the subscribe request.
This PR doesn't set the param to true
everywhere it's called—it only sets it to true
when calling Newspack_Newsletters_Contacts::subscribe()
following a form submission via the Newsletter Subscription Form block or Registration block. All other instances of Newspack_Newsletters_Contacts::subscribe()
should be unchanged.
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 don't feel confident... It seems we are circling back to something we intentionally tried to avoid.
WDYT of simply adding the other metadata that are part of newsletter subscription to the list of accepted metadata in the subscribe method. Currently it reads
$accepted_metadata = [ 'status', 'name' ];
Makes sense?
@miguelpeixe , if you can help us remember the rationale behind our choices here as well it would be awesome
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.
Hmm, but for these particular cases we'd want any valid metadata fields to be synced. Maybe we should be calling upsert()
instead of subscribe()
for signup requests from the blocks?
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.
Looking at this a bit more, it seems like the only real differences between subscribe
and upsert
methods are that the former allows for async execution, and it strips all metadata except for status
and name
keys. After that, subscribe
passes its data through to the upsert
method anyway.
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.
Wracking my memory for the reason behind these decisions...I think we wanted to retain the async option for certain newsletter signup flows so we could show an optimistic UI to make it feel faster, and show any errors to the user at a later point in their My Account dashboard. These are all of the flows where the async subscribe
method is currently used:
- Registration block
- Newsletter Subscription Form block
- RAS auth modal registration
- Post-modal-checkout newsletter signup modal
- Newsletter signup changes via the My Account dashboard
- A CLI command to resync premium newsletter memberships to premium newsletter signups (
wp newspack-newsletters sync-membership-tied-subscribers
)
I think for all of these except for the CLI command and the My Account page, we actually want all of the contact metadata to be synced to the ESP.
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.
it seems like the only real differences between subscribe and upsert methods are that the former allows for async execution, and it strips all metadata except for status and name keys.
A key difference is that it triggers a different action, that will trigger a different data event
idk, maybe we don't need to strip metadata out? I can't remember why this specific piece is there... would love to know if @miguelpeixe remembers
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.
IIRC, the rationale was mostly regarding the separation of concerns and better control of the data flow. subscribe()
is a user action to subscribe to list(s).
We're mixing names here. upsert()
is the lower-level method, used by both subscribe()
and sync()
.
sync()
is our async/background strategy for metadata updates.
I don't have a strong opinion on whether we should allow the metadata to be sent via subscribe()
or trigger a sync()
after the subscribe()
. I lean more to let sync()
be the sole owner of that task.
I'm not a fan of restoring the normalize contact data filter as proposed in Automattic/newspack-plugin#3779. It creates room for metadata coming from everywhere and debugging more difficult, as it was before the refactors.
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.
Looks like we're already firing a newspack_newsletters_contact_subscribed
action and newsletter_subscribed
with the unfiltered metadata after subscribing and syncing on the data event, but not including the metadata from the event payload. So if we include the metadata from this data event in the sync, then the changes in this PR are no longer necessary. See changes in 6b571e9 for details.
After these changes, we can remove the normalize contact data filter and rely on the syncs triggered by data events, since contact metadata from these events will be included in the triggered syncs, and metadata from queued syncs will be carried through to the single sync executed on shutdown.
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.
Ah, good call! I think that makes much more sense!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## release #1763 +/- ##
=============================================
+ Coverage 23.29% 23.33% +0.04%
- Complexity 2710 2724 +14
=============================================
Files 49 49
Lines 10754 10827 +73
=============================================
+ Hits 2505 2527 +22
- Misses 8249 8300 +51 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
All Submissions:
Changes proposed in this Pull Request:
With Automattic/newspack-plugin#3779, adds an optional param to allow contact metadata fields to be synced upon a
subscribe()
call. The cases we'd want this to happen are upon newsletter signup + account registration via Newsletter Subscription Form and Reader Registration blocks, where there may be account registration, referrer, and UTM meta fields captured during the signup, but not synced via the Newspack Plugin'sSync
classes.How to test the changes in this Pull Request:
Follow testing instructions in Automattic/newspack-plugin#3779.
Other information: