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

Create REST Endpoint GET:adsense-links for Analytics_4 module #8046

Closed
8 tasks done
tofumatt opened this issue Jan 6, 2024 · 3 comments
Closed
8 tasks done

Create REST Endpoint GET:adsense-links for Analytics_4 module #8046

tofumatt opened this issue Jan 6, 2024 · 3 comments
Labels
Module: AdSense Google AdSense module related issues Module: Analytics Google Analytics module related issues P1 Medium priority PHP Type: Enhancement Improvement of an existing feature

Comments

@tofumatt
Copy link
Collaborator

tofumatt commented Jan 6, 2024

Feature Description

Using the code added in #8045, we need to create a REST Route in our WordPress REST API Routes in the Analytics module for fetching AdSense accounts linked to Analytics accounts from the Google Analytics API.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • A new data point GET:adsense-links should be added to the Analytics_4 module.
  • It should take a GA4 Property ID as parameter and return the links between the provided GA4 property and AdSense account. ie. Google_Service_GoogleAnalyticsAdmin_GoogleAnalyticsAdminV1alphaAdSenseLink[]
  • If should not be shareable.

Implementation Brief

  • Once the required infrastructure is in place via #8084, we will have Google\Site_Kit\Modules\Analytics_4\GoogleAnalyticsAdmin\PropertiesAdSenseLinksService and a service (TBD. ie. analyticsadsenselinks).
  • In Google\Site_Kit\Modules\Analytics_4 class:
    • In get_datapoint_definitions() method, add GET:adsense-links datapoint with the aforementioned service.
    • In create_data_request() method, add a case for the above datapoint:
      • If $data['propertyID'] is not set, return with a missing_required_param error.
      • Otherwise, get the analyticsadsenselinks service and return $analyticsadmin->properties_adSenseLinks->listPropertiesAdSenseLinks( $parent ), where the $parent should be the normalized property ID. ie.self::normalize_property_id ($data['propertyID'] ).
    • In parse_data_response() method, add a case for the above datapoint:
      • Return (array) $response->getAdsenseLinks().

Test Coverage

  • Add PHPUnit test coverage for the newly added datapoint.

QA Brief

  • Connect the currently used GA4 property with an AdSense account.
  • Visit Site Kit
  • Run the following JS snippet in the console and verify that the connected AdSense accounts' client id is being returned inside the response.
const propertyID = googlesitekit.data.select('modules/analytics-4').getPropertyID();
await googlesitekit.api.get( 'modules', 'analytics-4', 'adsense-links', {propertyID}, {useCache: false});
  • The result should be of the following shape:
[
    {
        "name": "properties/285******/adSenseLinks/5*********",
        "adClientCode": "ca-pub-346*************"
    }
]

Changelog entry

  • Create REST endpoint to fetch Analytics AdSense links.
@tofumatt tofumatt added P0 High priority Module: Analytics Google Analytics module related issues Module: AdSense Google AdSense module related issues PHP labels Jan 6, 2024
@bethanylang bethanylang added P1 Medium priority and removed P0 High priority labels Jan 8, 2024
@kuasha420 kuasha420 assigned kuasha420 and unassigned kuasha420 Jan 11, 2024
@techanvil techanvil self-assigned this Jan 15, 2024
@techanvil
Copy link
Collaborator

IB ✅

@techanvil techanvil removed their assignment Jan 15, 2024
@kuasha420 kuasha420 added the Type: Enhancement Improvement of an existing feature label Jan 16, 2024
@ivonac4
Copy link
Collaborator

ivonac4 commented Jan 18, 2024

Adding this one to Sprint 119 since the dependency (8045) is in the CR, so it can at least be started.

@kuasha420 kuasha420 self-assigned this Jan 18, 2024
@kuasha420 kuasha420 removed their assignment Jan 27, 2024
@jimmymadon jimmymadon assigned jimmymadon and kuasha420 and unassigned jimmymadon Jan 29, 2024
@kuasha420 kuasha420 assigned jimmymadon and unassigned kuasha420 Jan 30, 2024
@jimmymadon jimmymadon removed their assignment Jan 30, 2024
@nfmohit nfmohit assigned nfmohit and unassigned nfmohit Jan 31, 2024
@mohitwp mohitwp self-assigned this Jan 31, 2024
@mohitwp
Copy link
Collaborator

mohitwp commented Feb 5, 2024

QA Update ✅

  • Tested on dev environment.
  • Verified the code snippet mentioned under QAB.
  • Verified that the connected AdSense accounts' client id is being returned inside the response.

image

image

@mohitwp mohitwp removed their assignment Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: AdSense Google AdSense module related issues Module: Analytics Google Analytics module related issues P1 Medium priority PHP Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

9 participants