Skip to content
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

[API Pull] Add Track Events to the Auth API responses #2452

Merged
merged 8 commits into from
Jul 8, 2024

Conversation

jorgemd24
Copy link
Contributor

@jorgemd24 jorgemd24 commented Jul 4, 2024

Changes proposed in this Pull Request:

Part of #2146 .

Currently, we have two tracking events, gla_disable_product_sync_click and gla_enable_product_sync_click. However, it would also be useful to track the status of the Auth flow and when merchants revoke access.

This PR adds the following server-side event tracking:

  • revoke_wpcom_api_authorization -> When the token is revoked, this event will include the status, blog id, and any error if it exists.
  • update_wpcom_api_authorization -> When the Auth flow is completed, this event will include the status, blog id, and any error if it exists.

Screenshots:

Detailed test instructions:

  1. Confirm tracking is allowed in WooCommerce > Settings > Advanced > Woo.com
  2. To view the tracking, go to Tracks -> History (live tracking doesn't show the properties). Filter by your username and the following events: wcadmin_gla_update_wpcom_api_authorization and wcadmin_gla_revoke_wpcom_api_auth. It may take some time for the data to appear.
  3. Alternatively you can use the following filter to see the events in the error log:
add_filter(
	'pre_http_request',
	function ( $pre, $args, $url ) {
		if ( str_starts_with( $url, 'https://pixel.wp.com' ) ) {
			wp_parse_str( wp_parse_url( $url, PHP_URL_QUERY ), $query_vars );
			error_log( json_encode( $query_vars, JSON_PRETTY_PRINT ) );
		}
		return $pre;
	},
	10,
	3
);

Ref: #2207

  1. Enable the notification service: add_filter( 'woocommerce_gla_notifications_enabled','__return_true' );
  2. Go to GLA -> Settings -> Get Early Access -> follow the steps.
  3. Revoke the access by clicking in : Disable product data fetch:

image

Additional details:

  • I included the blog_id because I thought it might help with debugging issues, but I can't see it in Tracks. I'm not sure why that is.

Changelog entry

@github-actions github-actions bot added type: enhancement The issue is a request for an enhancement. changelog: add A new feature, function, or functionality was added. labels Jul 4, 2024
Copy link

codecov bot commented Jul 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.8%. Comparing base (7ff8a9e) to head (2171ce6).
Report is 36 commits behind head on feature/google-api-project.

Additional details and impacted files

Impacted file tree graph

@@                      Coverage Diff                       @@
##             feature/google-api-project   #2452     +/-   ##
==============================================================
+ Coverage                          64.6%   64.8%   +0.1%     
  Complexity                         4552    4552             
==============================================================
  Files                               473     473             
  Lines                             17757   17783     +26     
==============================================================
+ Hits                              11478   11516     +38     
+ Misses                             6279    6267     -12     
Flag Coverage Δ
php-unit-tests 64.8% <100.0%> (+0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/API/WP/OAuthService.php 100.0% <100.0%> (+3.9%) ⬆️
src/MerchantCenter/AccountService.php 98.4% <100.0%> (+0.1%) ⬆️

... and 2 files with indirect coverage changes

@jorgemd24 jorgemd24 marked this pull request as ready for review July 4, 2024 20:33
@eason9487 eason9487 requested a review from a team July 5, 2024 06:21
@puntope puntope changed the title Add Track Events to the Auth API responses [API Pull] Add Track Events to the Auth API responses Jul 5, 2024
@puntope
Copy link
Contributor

puntope commented Jul 5, 2024

I included the blog_id because I thought it might help with debugging issues, but I can't see it in Tracks. I'm not sure why that is.

@jorgemd24 I yes get the blog ID (in the logs using the snippets. In tracks I didn0't check)


/**
* @event revoke_wpcom_api_auth
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add here the property directives? Also, I miss the event description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks I add them here: fb8b49c

/**
* @event revoke_wpcom_api_auth
*/
do_action(
Copy link
Contributor

Choose a reason for hiding this comment

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

@jorgemd24
Copy link
Contributor Author

Thanks @puntope for the review!

I yes get the blog ID (in the logs using the snippets. In tracks I didn0't check)

Yes, the blog_id is being sent to Tracks, and it shows in the logs, but I can't see it in Tracks. I'll need to investigate further to see if there are any restrictions on sending this parameter to Tracks.

Can you take another look to this PR?

@jorgemd24 jorgemd24 requested a review from puntope July 7, 2024 11:18
* @event revoke_wpcom_api_authorization
* @property string status The status of the request.
* @property string error The error message.
* @property mixed blog_id The blog ID.
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of mixed WDYT about number|null ?

Copy link
Contributor

@puntope puntope Jul 8, 2024

Choose a reason for hiding this comment

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

Also, maybe we can consider sending 400 or 500 for example or get the error code to have consistency between both woocommerce_gla_track_event tracks (in some is a number, the request status, and in this one the string "error" )

Copy link
Contributor

Choose a reason for hiding this comment

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

error seems to be optional

* When the WPCOM token has been revoked with errors.
*
* @event revoke_wpcom_api_authorization
* @property string status The status of the request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Status is number in this case right?

Copy link
Contributor

@puntope puntope left a comment

Choose a reason for hiding this comment

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

Thanks @jorgemd24 for adding the docs. I left some additional comments

@jorgemd24
Copy link
Contributor Author

Hi @puntope,

I addressed your suggestions. Can u have another look? Thanks

* When the WPCOM token has been revoked successfully.
*
* @event revoke_wpcom_api_authorization
* @property string status The status of the request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing to refactor the status, is also int here.

Copy link
Contributor

@puntope puntope left a comment

Choose a reason for hiding this comment

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

Thx @jorgemd24 approved in advance. However, I miss some doc tweak in one of the revoke_wpcom_api_authorization

@jorgemd24 jorgemd24 merged commit 422f3f6 into feature/google-api-project Jul 8, 2024
10 checks passed
@jorgemd24 jorgemd24 deleted the add/track-event-auth-wpcom branch July 8, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants