Skip to content

fix(ga4): fire login/registration activities via SSO#3965

Merged
dkoo merged 5 commits into
trunkfrom
fix/activities-via-sso
May 19, 2025
Merged

fix(ga4): fire login/registration activities via SSO#3965
dkoo merged 5 commits into
trunkfrom
fix/activities-via-sso

Conversation

@dkoo

@dkoo dkoo commented May 8, 2025

Copy link
Copy Markdown
Contributor

All Submissions:

Changes proposed in this Pull Request:

Plugs a hole in the reader_logged_in and reader_registered activities/GA4 events implemented in #3895. Logins and registrations via SSO were not firing these activities, and thus not triggering GA4 events to track these user interactions.

This PR ensures that logins and registrations via SSO will fire these activities and events. It also adds a new sso boolean parameter which is only set if the activity originated via an SSO flow. It also refactors the front-end analytics handlers to reduce some code duplication.

How to test the changes in this Pull Request:

  1. Check out this branch.
  2. In incognito sessions, register new accounts using the "Sign in with Google" button, using both the Registration block and in the Sign In modal.
  3. Confirm that reader_registered reader activities are fired (look in Dev Tools > localStorage > np_reader_1_activity) and np_reader_registered GA4 events are fired with relevant params, including the new sso param.
  4. In new incognito sessions, log into the accounts created in step 2 using the "Sign in with Google" button, using both the Registration block and in the Sign In modal.
  5. Confirm that reader_logged_in reader activities are fired (look in Dev Tools > localStorage > np_reader_1_activity) and np_reader_logged_in GA4 events are fired with relevant params, including the new sso param.
  6. Smoke test other GA4 events as described in fix(analytics): migrate back-end GA4 events to front-end #3895 and confirm that there are no other changes in those events' behavior or data.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo self-assigned this May 8, 2025
@dkoo dkoo added the [Status] Needs Review The issue or pull request needs to be reviewed label May 8, 2025
@dkoo dkoo requested a review from a team as a code owner May 8, 2025 22:24

@miguelpeixe miguelpeixe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The event parameters look good for both auth modal and block, but I'm unable to get the SSO to trigger a reader_registered event. It's always reader_logged_in regardless of account creation.

Also, not sure if related to this PR, but creating an account via SSO is not logging me in. Only after I SSO again (with the account created) that I'm authenticated.

Comment thread src/reader-activation/analytics.js Outdated
@dkoo dkoo requested a review from miguelpeixe May 12, 2025 17:24
@dkoo

dkoo commented May 13, 2025

Copy link
Copy Markdown
Contributor Author

The event parameters look good for both auth modal and block, but I'm unable to get the SSO to trigger a reader_registered event. It's always reader_logged_in regardless of account creation.

8bd85c7 fixes this for both the Registration block and Sign In modal—now you should be able to get reader_registered events when registering, and reader_logged_in when logging in.

Also, not sure if related to this PR, but creating an account via SSO is not logging me in. Only after I SSO again (with the account created) that I'm authenticated.

I'm not able to replicate this. After registering for a new account via SSO in either case, I'm logged in. Maybe it's related to Automattic/newspack-popups#1436? I noticed that without that fix, I was seeing strange behavior in the reader data store.

@dkoo dkoo changed the base branch from alpha to trunk May 14, 2025 20:38
@dkoo

dkoo commented May 14, 2025

Copy link
Copy Markdown
Contributor Author

@miguelpeixe I rebased to trunk. Looks like we lost the login/registration/newsletter events there somehow (they are still in release), so this PR now restores them.

@miguelpeixe

Copy link
Copy Markdown
Member

The events weren't lost, they migrated to the new strategy using the registerActivityEvent():

registerActivityEvent( 'reader_registered', data => ( {
registration_method: data?.registration_method || 'unknown',
} ) );
registerActivityEvent( 'reader_logged_in', data => ( {
login_method: data?.login_method || 'unknown',
} ) );
registerActivityEvent(
'newsletter_signup',
data => ( {
newsletters_subscription_method:
data?.newsletters_subscription_method || 'unknown',
lists: data?.lists || [],
} ),
'np_newsletter_subscribed'
);

@dkoo

dkoo commented May 19, 2025

Copy link
Copy Markdown
Contributor Author

@miguelpeixe whoops, I forgot, sorry! 8bb8e40 removes them again and also adds a missing piece of data to the payload when logging in using a password.

@miguelpeixe miguelpeixe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! Thank you for the revisions

@github-actions github-actions Bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels May 19, 2025
@dkoo dkoo merged commit 8c97515 into trunk May 19, 2025
8 checks passed
@dkoo dkoo deleted the fix/activities-via-sso branch May 19, 2025 19:47
@github-actions

Copy link
Copy Markdown

Hey @dkoo, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

matticbot pushed a commit that referenced this pull request May 23, 2025
# [6.7.0-alpha.1](v6.6.2...v6.7.0-alpha.1) (2025-05-23)

### Bug Fixes

* **404-images:** use JS without modifying content ([#3963](#3963)) ([9f5646b](9f5646b))
* add missing namespace ([#3980](#3980)) ([6d58793](6d58793))
* **emails:** add missing HTML markup in the change-email-cancel template ([#3981](#3981)) ([040ae30](040ae30))
* **ga4:** fire login/registration activities via SSO ([#3965](#3965)) ([8c97515](8c97515))
* hide modal content gate when modal checkout is opened ([#3953](#3953)) ([a503973](a503973))
* **jetpack:** handle the related posts max age option ([#3964](#3964)) ([8aad2b8](8aad2b8))
* make sure fix duplcate fields apply filters ([#3971](#3971)) ([f361a4e](f361a4e))
* namespace Lite Site ([#3975](#3975)) ([e4665ae](e4665ae))
* sync correction status with parent post status ([#3978](#3978)) ([dcd5a12](dcd5a12))

### Features

* add compatibility to network in custom bylines ([#3972](#3972)) ([199a993](199a993))
* add icons repository and remove custom icons ([#3883](#3883)) ([e56d2e0](e56d2e0))
* **analytics:** "My Account" dashboard interactions ([#3949](#3949)) ([22e9590](22e9590))
* **donations:** update notice style and type ([#3962](#3962)) ([3f60ef3](3f60ef3))
* **email-change:** remove env constant requirement ([#3943](#3943)) ([4158bf1](4158bf1))
* **my-account:** apply Newspack UI styles to My Account w/ env constant ([#3951](#3951)) ([e4aa5a2](e4aa5a2))
* **my-account:** full-site takeover template and custom nav menu ([#3974](#3974)) ([5cf8403](5cf8403))
* **woocommerce:** log error notices ([#3952](#3952)) ([1654007](1654007))
@matticbot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 6.7.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jun 2, 2025
# [6.7.0](v6.6.4...v6.7.0) (2025-06-02)

### Bug Fixes

* **404-images:** use JS without modifying content ([#3963](#3963)) ([9f5646b](9f5646b))
* add missing namespace ([#3980](#3980)) ([6d58793](6d58793))
* **emails:** add missing HTML markup in the change-email-cancel template ([#3981](#3981)) ([040ae30](040ae30))
* **ga4:** fire login/registration activities via SSO ([#3965](#3965)) ([8c97515](8c97515))
* hide modal content gate when modal checkout is opened ([#3953](#3953)) ([a503973](a503973))
* **jetpack:** handle the related posts max age option ([#3964](#3964)) ([8aad2b8](8aad2b8))
* make sure fix duplcate fields apply filters ([#3971](#3971)) ([f361a4e](f361a4e))
* namespace Lite Site ([#3975](#3975)) ([e4665ae](e4665ae))
* prevent auto-publishing corrections when scheduling posts ([#4006](#4006)) ([7531832](7531832))
* sync correction status with parent post status ([#3978](#3978)) ([dcd5a12](dcd5a12))

### Features

* add compatibility to network in custom bylines ([#3972](#3972)) ([199a993](199a993))
* add icons repository and remove custom icons ([#3883](#3883)) ([e56d2e0](e56d2e0))
* **analytics:** "My Account" dashboard interactions ([#3949](#3949)) ([22e9590](22e9590))
* **donations:** update notice style and type ([#3962](#3962)) ([3f60ef3](3f60ef3))
* **email-change:** remove env constant requirement ([#3943](#3943)) ([4158bf1](4158bf1))
* **my-account:** apply Newspack UI styles to My Account w/ env constant ([#3951](#3951)) ([e4aa5a2](e4aa5a2))
* **my-account:** full-site takeover template and custom nav menu ([#3974](#3974)) ([5cf8403](5cf8403))
* **woocommerce:** log error notices ([#3952](#3952)) ([1654007](1654007))
@matticbot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 6.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released on @alpha released [Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants