From 9ac1c3378f188794de63c9947ca7e46f5dd8644c Mon Sep 17 00:00:00 2001 From: leogermani Date: Mon, 21 Aug 2023 15:24:52 -0300 Subject: [PATCH] feat: add anonymized email to ga4 events (#2585) * feat: add anonymized email to ga4 events * feat: rename property --- includes/data-events/connectors/ga4/README.md | 1 + includes/data-events/connectors/ga4/class-ga4.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/data-events/connectors/ga4/README.md b/includes/data-events/connectors/ga4/README.md index 4373472d6c..4dd4031bc7 100644 --- a/includes/data-events/connectors/ga4/README.md +++ b/includes/data-events/connectors/ga4/README.md @@ -26,6 +26,7 @@ These parameters are added to all events: * `ga_session_id`: The GA Session ID, retrieved from the cookie * `logged_in`: Whether the user is logged in when the event got fired * `is_reader`: Whether the user is a RAS reader +* `email_hash`: The anonymized user email, if the user is logged in Note: All paramaters are strings diff --git a/includes/data-events/connectors/ga4/class-ga4.php b/includes/data-events/connectors/ga4/class-ga4.php index 28d2fa7fb5..3859c5850a 100644 --- a/includes/data-events/connectors/ga4/class-ga4.php +++ b/includes/data-events/connectors/ga4/class-ga4.php @@ -189,8 +189,9 @@ public static function filter_event_body( $body, $event_name ) { $body['data']['ga_params']['is_reader'] = 'no'; if ( is_user_logged_in() ) { - $current_user = wp_get_current_user(); - $body['data']['ga_params']['is_reader'] = Reader_Activation::is_user_reader( $current_user ) ? 'yes' : 'no'; + $current_user = wp_get_current_user(); + $body['data']['ga_params']['is_reader'] = Reader_Activation::is_user_reader( $current_user ) ? 'yes' : 'no'; + $body['data']['ga_params']['email_hash'] = md5( $current_user->user_email ); } return $body;