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
45 stars 21 forks source link

Label campaigns for the web version and the WC Mobile app #2514

Closed jorgemd24 closed 1 month ago

jorgemd24 commented 1 month ago

Changes proposed in this Pull Request:

Part of pcTzPl-2nS-p2

This PR will automatically label campaigns created via the WC Mobile App by checking the user agent headers. The labels used will be wc-android or wc-ios. If the campaign isn't created through the WC Mobile App, it will be labeled as wc-web.

Screenshots:

Detailed test instructions:

  1. Download the WC Mobile App and connect it to one of your local sites. Then, navigate to WC Admin -> Google for WooCommerce and create a new campaign. Alternatively, simulate this process by sending a request to POST /wp-json/wc/gla/ads/campaigns with the User Agent header set to something like: Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 wc-ios/19.7.1. Set the below body:
{
    "amount": 0.01,
    "targeted_locations": ["ES"],
}
  1. Follow the steps mentioned in this PR to check if the label has been set: https://github.com/woocommerce/google-listings-and-ads/pull/2485. It has to be wc-ios or wc-android.
  2. Repeat the process on a laptop, and the campaign label should be wc-web

Additional details:

Changelog entry

Tweak - Label campaigns for the web version and the WooCommerce Mobile app.

jorgemd24 commented 1 month ago

Hi @mikkamp thanks for the review! I liked your suggestion about detecting the user agent in the client, (see my comment) so I went ahead and I moved the logic to the client. Can you have another look? Thanks.

codecov[bot] commented 1 month ago

Codecov Report

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

Project coverage is 64.7%. Comparing base (182b5dd) to head (aa6185e). Report is 6 commits behind head on develop.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514/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/2514?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) ```diff @@ Coverage Diff @@ ## develop #2514 +/- ## ============================================ + Coverage 63.5% 64.7% +1.2% - Complexity 0 4580 +4580 ============================================ Files 322 798 +476 Lines 5043 22940 +17897 Branches 1220 1222 +2 ============================================ + Hits 3204 14844 +11640 - Misses 1672 7930 +6258 + Partials 167 166 -1 ``` | [Flag](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [js-unit-tests](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | `63.8% <100.0%> (+0.2%)` | :arrow_up: | | [php-unit-tests](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | `65.0% <100.0%> (?)` | | 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/2514?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [js/src/data/actions.js](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514?src=pr&el=tree&filepath=js%2Fsrc%2Fdata%2Factions.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#diff-anMvc3JjL2RhdGEvYWN0aW9ucy5qcw==) | `5.2% <100.0%> (+3.6%)` | :arrow_up: | | [js/src/utils/isMobileApp.js](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514?src=pr&el=tree&filepath=js%2Fsrc%2Futils%2FisMobileApp.js&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#diff-anMvc3JjL3V0aWxzL2lzTW9iaWxlQXBwLmpz) | `100.0% <100.0%> (ø)` | | | [...rc/API/Site/Controllers/Ads/CampaignController.php](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514?src=pr&el=tree&filepath=src%2FAPI%2FSite%2FControllers%2FAds%2FCampaignController.php&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#diff-c3JjL0FQSS9TaXRlL0NvbnRyb2xsZXJzL0Fkcy9DYW1wYWlnbkNvbnRyb2xsZXIucGhw) | `100.0% <100.0%> (ø)` | | ... and [475 files with indirect coverage changes](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2514/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce)
jorgemd24 commented 1 month ago

Thanks @mikkamp for the review! I've addressed all your comments.

Just looking at this track here. Wouldn't it be useful to also pass the source? Or is it going to still include the user agent string so it can be extracted from there?

I think it is good to add the source in the event tracking so I've added it here: aa6185e