woocommerce / google-listings-and-ads

Sync your store with Google to list products for free, run paid ads, and track performance straight from your store dashboard.
https://woo.com/products/google-listings-and-ads/
GNU General Public License v3.0
44 stars 21 forks source link

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

Closed jorgemd24 closed 1 month ago

jorgemd24 commented 1 month ago

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:

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: https://github.com/woocommerce/google-listings-and-ads/pull/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:

Changelog entry

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452/graphs/tree.svg?width=650&height=150&src=pr&token=UROWUPF1LX&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce)](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) ```diff @@ 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](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [php-unit-tests](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | `64.8% <100.0%> (+0.1%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [src/API/WP/OAuthService.php](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452?src=pr&el=tree&filepath=src%2FAPI%2FWP%2FOAuthService.php&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#diff-c3JjL0FQSS9XUC9PQXV0aFNlcnZpY2UucGhw) | `100.0% <100.0%> (+3.9%)` | :arrow_up: | | [src/MerchantCenter/AccountService.php](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452?src=pr&el=tree&filepath=src%2FMerchantCenter%2FAccountService.php&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#diff-c3JjL01lcmNoYW50Q2VudGVyL0FjY291bnRTZXJ2aWNlLnBocA==) | `98.4% <100.0%> (+0.1%)` | :arrow_up: | ... and [2 files with indirect coverage changes](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2452/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce)
puntope commented 1 month ago

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)

jorgemd24 commented 1 month ago

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 commented 1 month ago

Hi @puntope,

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