-
Notifications
You must be signed in to change notification settings - Fork 43
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(modal-checkout): handle auth modal analytics #1908
fix(modal-checkout): handle auth modal analytics #1908
Conversation
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.
Nice work @miguelpeixe!
This works as expected. I just had one question about using a flag for open state before giving a thumbs up.
Also had a second non-blocking question/nit but feel free to ignore that one!
src/modal-checkout/modal.js
Outdated
let getProductDataModal = {}; | ||
// Track the checkout state for analytics. | ||
let analyticsData = {}; | ||
let checkoutOpen = 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.
Is this flag necessary? Can we just use the data-state
of the modal checkout container which will be open
when the modal is open and closed
when not?
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.
The checkoutOpen
is also set to true
when an anonymous reader intent to purchase triggers the auth modal. In this case, we can't leverage the checkout modal state because it's not yet open at this point.
We can rename the variable or have a different strategy, but I don't think going through each modal state would be practical for this.
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 updated the variable name and added a comment in 94fea3f. I think this change makes it more clear that it's not about the checkout modal being open. Let me know if you think this works
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 works for me! Thanks for clarifying @miguelpeixe 👍
src/modal-checkout/modal.js
Outdated
@@ -389,6 +403,12 @@ domReady( () => { | |||
console.warn( 'Unable to generate cart:', error ); // eslint-disable-line no-console | |||
} ); | |||
}, | |||
onClose: () => { |
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.
Non-blocking nit/question. Feels weird to provide an onClose
callback option that won't be called everytime. Especially considering we already provide a generic callback
option. Is it possible to simply use the callback
for analytics purposes here, using the authData
and open state as a flag for whether this was dismissed?
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.
My concern is that the callback
is only called on success, so, as is, we don't have a way to hook into dismissals.
I think we can go 2 ways:
- Make the
callback
also trigger on dismissals, including the success/error/dismiss as a callback argument - Change
callback
toonSuccess
and preserveonClose
(or rename toonDismiss
)
WDYT?
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.
Change callback to onSuccess and preserve onClose (or rename to onDismiss)
I like the idea of onSuccess/onDismiss. I feel this makes it super clear where functionality for each should go. But truthfully I'm fine with either approach if you have a preference for 1
.
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 also like 2 better 😄
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.
Updated in 89aacb6 and Automattic/newspack-plugin@cda1b5c. I've also introduced the onError
callback and updated the newsletter signup modal to follow the same standard.
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.
add the following to line 24 of src/modal-checkout/analytics/ga4/utils/index.js for easier testing
Would be neat if we could make this logging permanent and only have it enabled when some development flag is present or something like that. Definitely not something needed in this PR, but thought I'd bring it up.
That can be handy. I usually use browser extensions to track GA behavior on a page. I just figured the console log would be more straightforward for this PR than suggesting an extension. |
This reverts commit f958d86.
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 good! Thanks for the changes @miguelpeixe!
All Submissions:
Changes proposed in this Pull Request:
1200530782742699-as-1208558693529961/f
When a reader starts the modal checkout they may get prompted to authenticate or register, which will not trigger the GA4 event to register the intent.
This PR, along with Automattic/newspack-plugin#3481, implements that support.
Along with that:
form_submission
eventHow to test the changes in this Pull Request:
src/modal-checkout/analytics/ga4/utils/index.js
for easier testing:opened
event is logged in the consoledismissed
event is logged in the console with the correct payloadopened
event (checkoutOpen
changed tofalse
)opened
eventform_submission
event is triggered with the correct payloaddismissed
eventopened_variations
eventopened
event is triggereddismissed
is triggeredopened_variations
triggers againOther information: