question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extract new global for tracking configuration

See original GitHub issue

Feature Description

Initially, custom metadata used for Site Kit’s custom dimensions when tracking internal events all came from the _googlesitekitBaseData global which is loaded across all wp-admin (for users that can use Site Kit).

As this has evolved, it now includes data from other globals which include additional data that we wouldn’t want to load everywhere. Similarly, there is some data within the base global which is only used for tracking that we don’t need globally either.


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

Acceptance criteria

  • A new googlesitekit-tracking-data Script Data Asset should be registered which populates a new _googlesitekitTrackingData global
    • The data object should contain all of the properties sourced from base and user globals by trackEvent
    • Any properties which are only used for tracking may be removed from their previous objects (e.g. userIDHash), properties with existing non-tracking uses should be duplicated (e.g. referenceSiteURL)
  • The new data asset should be added to the top-level list of $dependencies used by all SK screens in Assets
  • The tracking configuration in assets/js/util/tracking/index.js should be updated to source the tracking configuration values from the new tracking-specific global only
    • The one exception to this is GOOGLESITEKIT_VERSION which is an injected top-level global

Implementation Brief

  • In includes/Core/Assets/Assets.php, get_assets() method:

    • Add googlesitekit-tracking-data to the top of the $dependencies array list.
    • Add a new Script_Data() with the handle of googlesitekit-tracking-data and global of _googlesitekitTrackingData.
    • In the data_callback make a call to a new method $this->get_inline_tracking_data which contains following properties sourced from the base and user globals by trackEvent:
      • referenceSiteURL,
      • userIDHash,
    • The get_inline_tracking_data method should return apply_filters( 'googlesitekit_inline_tracking_data', $inline_data ).
    • Remove the userIDHash property from the get_inline_base_data() method.
  • In includes/Core/Authentication/Authentication.php, add a private method inline_js_tracking_data with the following:

    • Should receive $data param
    • The isAuthenticated property gets data from is_authenticated() method.
    • The userRoles property gets data from wp_get_current_user()->roles method.
    • Return the $data.
    • In the register method add a apply_filter() with
      add_filter( 'googlesitekit_inline_tracking_data', $this->get_method_proxy( 'inline_js_tracking_data' ) );
      
  • In includes/Core/Tracking/Tracking.php:

    • Rename the inline_js_base_data method to inline_js_tracking_data.
    • In the register method replace the apply_filter() with
    add_filter( 'googlesitekit_inline_tracking_data', $this->get_method_proxy( 'inline_js_tracking_data' ) );
    
  • In includes/Core/Modules/Modules.php, add apply_filter() for googlesitekit_inline_tracking_data similar to googlesitekit_inline_base_data. See: https://github.com/google/site-kit-wp/blob/fd56e5f5fb38b18afe98828d7473e3d13c1905da/includes/Core/Modules/Modules.php#L339-L355

  • Consider creating a private method inline_js_tracking_active_modules to reuse in both the hooks.

  • In assets/js/util/tracking/index.js:

    • Use global._googlesitekitTrackingData to destructure the events instead of global._googlesitekitBaseData.
  • In .storybook/utils/resetGlobals.js, add all the trackEvent properties under global._googlesitekitTrackingData = {}.

  • Remove the properties we are removing from the global._googlesitekitBaseData object.

Test Coverage

  • No new tests are to be added.

QA Brief

  • This issue modifies the internal code which fetches data that is passed to GA events as dimension1 to dimension7. Thus, they should be tested using the GA Debugger. Verify these dimensions are populated as before and are not changed in any way.

QA Eng

  • Verify a new global window._googlesitekitTrackingData is populated as per the AC.

Changelog entry

  • Move tracking related data into its own global _googlesitekitTrackingData variable.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
jimmymadoncommented, Jun 17, 2022

@wpdarren Testing 3-5 events should be sufficient as if it works for a few, it should work for all.

1reaction
eugene-manuilovcommented, Jun 10, 2022

Very nice. Thanks, @hussain-t. IB ✔️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Report on 'Not Sent' subscribers through email sends
Retrieve the subscribers who were not successfully sent to through a Tracking Extract. Note: If Tracking Extracts are not available in your ...
Read more >
Configuring Global Settings for Item Tracking - TechDocs
The item tracking data is stored in the file system of the Notification Server computer. You can edit the default location of the...
Read more >
Enable change tracking for entities - Dynamics 365
In the Data management workspace, select Configure entity export to database. Select the database to export data to, and then select Publish.
Read more >
Configure and Capture Embedded Packet on Software - Cisco
The Packet Capture Config Generator and Analyzer tool is available for Cisco Customers to aid in the configuration, capture, and extraction ...
Read more >
Go Custom Instrumentation - Datadog Docs
Returns the new span, and a new context containing the new span. span, ctx := tracer. ... Configure extraction styles using the environment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found