Skip to content

Deprecation error for users when using the Ads module #9531

Closed
@adamdunnage

Description

Bug Description

We have had a couple of reports in the support forum of the following Ads deprecation error:

Deprecated: Creation of dynamic property Google\Site_Kit\Modules\Ads\Web_Tag::$home_domain is deprecated in /home/w4397664/public_html/wp-content/plugins/google-site-kit/includes/Modules/Ads/Web_Tag.php on line 37

Like with many of these errors, it doesn't appear to have an impact in the Site Kit plugin but it's likely something that needs addressing with how we deal with the Ads module.

Example support topic: https://wordpress.org/support/topic/deprecated-creation-of-dynamic-property-google/

Steps to reproduce

N/A

Screenshots

Additional Context


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

Acceptance criteria

  • The deprecation notice mentioned in the issue description should no longer be raised.

Implementation Brief

  • In includes/Modules/Ads/Web_Tag.php:
    • Use the Core\Tags\Tag_With_Linker_Trait trait.
    • Remove the set_home_domain method as it is already identically available in the above trait.

The above should fix the reported issue. However, I see another potential issue with this class. The class accepts a home domain, but doesn't exactly embed this tag config as a linker command in the tag. As it is a simple improvement, the following can be done to solve this:

  • In includes/Modules/Ads/Web_Tag.php:
    • Add a protected get_tag_config method:
      • Call the add_linker_to_tag_config method, passing an empty array to it as a parameter and return its value.
    • Update the setup_gtag method:
      • Call the get_tag_config method and store its value in a variable named $gtag_opt.
      • Add the linker to the GTag similar to how it is done in Modules\Analytics_4\Web_Tag::setup_gtag.

Test Coverage

  • Update any failing tests.

QA Brief

  • The reported notice is only visible within the debug logs in PHP versions 8.2 and above.
  • Set up the Ads module.
  • Verify that the notice does not show up anymore.

Changelog entry

  • Fix the deprecation error in the Ads module related to the creation of a dynamic property in the Web_Tag class.

Metadata

Assignees

No one assigned

    Labels

    Module: AdsGoogle Ads module related issuesP2Low priorityPHPTeam MIssues for Squad 2Type: SupportSupport request

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions