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

Implement GA4 logic in server-side callback for creating a new Analytics account #3252

Closed
felixarntz opened this issue Apr 29, 2021 · 7 comments
Labels
Module: Analytics Google Analytics module related issues P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature
Milestone

Comments

@felixarntz
Copy link
Member

felixarntz commented Apr 29, 2021

In the server-side callback where a new Analytics account has been created, if the ga4setup flag is active, a corresponding GA4 property should be created as well.


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

Acceptance criteria

  • In Analytics::handle_provisioning_callback a new action should be triggered right before redirecting the user googlesitekit_analytics_handle_provisioning_callback.
  • Then in the Analytics_4 class a callback should be added to that action which creates a corresponding new GA4 property and GA4 web data stream and stores their data in the respective Analytics_4\Settings settings.
    • Since the respective data points for creating a GA4 property and creating a GA4 web data stream already rely on the current website (e.g. for name and URL), it's not really necessary to have any additional context on which account/property/profile were created. It is just a new one for the current site.
    • If any of these API requests fails, it should be ignored / not result in a user-facing error or blocking behavior.

Implementation Brief

  • Trigger the new googlesitekit_analytics_handle_provisioning_callback action right before the final redirect in the Analytics::handle_provisioning_callback() method.
    • The action should retrieve account ID, property ID, profile ID, and internal web property ID as action arguments.
  • Extract the property creation script into a new private method create_property( $accountID ):
    $property = new Google_Service_GoogleAnalyticsAdmin_GoogleAnalyticsAdminV1alphaProperty();
    $property->setParent( self::normalize_account_id( $data['accountID'] ) );
    $property->setDisplayName( wp_parse_url( $this->context->get_reference_site_url(), PHP_URL_HOST ) );
    return $this->get_service( 'analyticsadmin' )->properties->create( $property );
  • Extract the web data stream creation script into a new private method create_webdatastream( $propertyID ):
    $datastream = new Google_Service_GoogleAnalyticsAdmin_GoogleAnalyticsAdminV1alphaWebDataStream();
    $datastream->setDisplayName( wp_parse_url( $this->context->get_reference_site_url(), PHP_URL_HOST ) );
    $datastream->setDefaultUri( $this->context->get_reference_site_url() );
    return $this->get_service( 'analyticsadmin' )->properties_webDataStreams->create( self::normalize_property_id( $data['propertyID'] ), $datastream );
  • Add a new private method handle_provisioning_callback( $accountID ) to the Analytics_4 class.
    • In the method body, create a new ga4 property and web datastream using new helper methods.
    • Save new propertyID and webDataStreamID in the Analytics4 settings.
    • Suppress any error triggered during the creation of new property and web data stream because the ga4 API is still in the alpha phase. Add a to-do note to remove error suppression once ga4 API becomes stable.
  • Add a new hook to the Analytics_4::register method that calls the new handle_provisioning_callback method for the googlesitekit_analytics_handle_provisioning_callback action.

Test Coverage

  • N/A

Visual Regression Changes

  • N/A

QA Brief

  • Check the Analytics_4 class that it has the handle_provisioning_callback method which is connected to the googlesitekit_analytics_handle_provisioning_callback action in the register method.
  • Check that the Analytics_4::handle_provisioning_callback method creates a new property and web data stream for the provided account ID.
  • Check the Analytics::handle_provisioning_callback() method and make sure that it triggers the googlesitekit_analytics_handle_provisioning_callback action at the very end and before the success redirect.

Changelog entry

  • Update Analytics account provisioning to create a corresponding GA4 property as well.
@felixarntz felixarntz added P0 High priority Type: Enhancement Improvement of an existing feature Module: Analytics Google Analytics module related issues labels Apr 29, 2021
@felixarntz felixarntz assigned felixarntz and unassigned felixarntz Apr 29, 2021
@eugene-manuilov eugene-manuilov added the QA: Eng Requires specialized QA by an engineer label May 5, 2021
@eclarke1 eclarke1 added this to the Sprint 49 milestone May 7, 2021
@tofumatt tofumatt self-assigned this May 11, 2021
@tofumatt
Copy link
Collaborator

Looks good, just one question:

Suppress any error triggered during the creation of new property and web data steam.

I'm guessing we want to do this because the API is new/unstable? But maybe we should mention why in the IB or make it explicit there to include a comment why we're silencing errors rather than surfacing them, or we could get weird bugs in the future. Or, at least, developers might be confused when they see the code and wonder why we're doing that.

What do you think @eugene-manuilov?

@eugene-manuilov
Copy link
Collaborator

@tofumatt ok, updated it. Could you please check it one more time?

@tofumatt
Copy link
Collaborator

Thanks!

IB ✅

@tofumatt tofumatt removed their assignment May 13, 2021
@fhollis fhollis modified the milestones: Sprint 49, Sprint 50 May 20, 2021
@eugene-manuilov eugene-manuilov self-assigned this May 24, 2021
@johnPhillips
Copy link
Contributor

Un-assigning myself as I'm not sure my PHP is currently up to the task!

@johnPhillips johnPhillips removed their assignment May 26, 2021
@eugene-manuilov eugene-manuilov self-assigned this May 26, 2021
@eugene-manuilov eugene-manuilov removed their assignment May 31, 2021
@aaemnnosttv aaemnnosttv self-assigned this Jun 2, 2021
@aaemnnosttv
Copy link
Collaborator

@eugene-manuilov please add a QAB 👍

@eugene-manuilov
Copy link
Collaborator

QAB is added.

@eugene-manuilov eugene-manuilov removed their assignment Jun 4, 2021
@asvinb
Copy link
Collaborator

asvinb commented Jun 7, 2021

QA: ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Analytics Google Analytics module related issues P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

8 participants