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

Issue / 8777 Prevent Conversion Tracking When Toggled Off #8779

Merged

Conversation

10upsimon
Copy link
Collaborator

@10upsimon 10upsimon commented May 31, 2024

Summary

Addresses issue:

Relevant technical choices

  • Added gating of event provider script enqueue if conversion tracking is not enabled.
  • Updated test suite for Conversion_TrackingTest to add test that asserts scripts are not enqueued when conversion tracking is disabled.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

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

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

Copy link

github-actions bot commented May 31, 2024

Build files for a461c55 have been deleted.

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

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

Thanks @10upsimon I left you 1 comment

Copy link
Collaborator

@zutigrm zutigrm left a comment

Choose a reason for hiding this comment

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

@10upsimon Nice one, LGTM

Copy link
Collaborator

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

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

Thanks @10upsimon – this LGTM, just a few small changes to clean this up.

@@ -96,7 +96,7 @@ public function register() {
'wp_enqueue_scripts',
function() {
// Do nothing if neither Ads nor Analytics snippet has been inserted.
if ( ! did_action( 'googlesitekit_ads_init_tag' ) && ! did_action( 'googlesitekit_analytics-4_init_tag' ) ) {
if ( ! $this->conversion_tracking_settings->is_conversion_tracking_enabled() || ( ! did_action( 'googlesitekit_ads_init_tag' ) && ! did_action( 'googlesitekit_analytics-4_init_tag' ) ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's split these onto separate lines as it's quite hard to read as one long line especially with extra parenthesis.

Also, the implementation is getting a bit large to be inline here, let's extract it to a method to keep register focused on just registration.

Comment on lines 63 to 67
$original_conversion_tracking_settings = array(
'enabled' => true,
);

$this->conversion_tracking_settings->set( $original_conversion_tracking_settings );
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be needed since changes to options shouldn't persist between tests as WP will rollback the transaction. Feel free to double check to make sure though 👍

Comment on lines 80 to 84
$original_conversion_tracking_settings = array(
'enabled' => false,
);

$this->conversion_tracking_settings->set( $original_conversion_tracking_settings );
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about this?

Suggested change
$original_conversion_tracking_settings = array(
'enabled' => false,
);
$this->conversion_tracking_settings->set( $original_conversion_tracking_settings );
$this->conversion_tracking_settings->set( array( 'enabled' => false ) );

@aaemnnosttv aaemnnosttv merged commit 9b5566c into develop May 31, 2024
17 of 19 checks passed
@aaemnnosttv aaemnnosttv deleted the issue/8777-prevent-conversion-tracking-when-toggled-off branch May 31, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants