site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Make filtering Analytics options available to developers

Open bjackson27 opened this issue 7 years ago • 3 comments

Feature Description

Introduce a filter for analytics parameters on the FE.


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

Acceptance criteria

  • There is already a googlesitekit_gtag_opt filter for the regular Analytics configuration options in https://github.com/google/site-kit-wp/blob/develop/includes/Modules/Analytics.php#L276. That filter is sufficient for this part, however its doc-block should clarify that it filters configuration options for the Analytics snippet. Not as many people understand what "gtag" is right away (at the same time, the doc-block should continue to mention that this is for gtag, to differentiate it from other Analytics snippet types people might be familiar with).
  • To cover AMP, an additional googlesitekit_amp_gtag_opt filter should be introduced, for the object that is passed to amp-analytics as JSON in the Analytics module. The docs should have a @see annotation pointing to https://developers.google.com/gtagjs/devguide/amp.
  • A key requirement for the AMP filter is that the tracking ID itself must not be changed (for the non-AMP filter, the tracking ID isn't part of the options anyway). In order to ensure that, logic should be added after running the filter that resets the tracking ID value to the original one (in case someone tried to change it). All other properties should be freely customizable.

Implementation brief

  • Update doc-block for googlesitekit_gtag_opt filter clarifying that it filters configuration options for the Analytics snippet. Keep mention that is for gtag. https://github.com/google/site-kit-wp/blob/4c691659af7d975205be2957e2e7d36b26f9e8e7/includes/Modules/Analytics.php#L268

  • Add filter googlesitekit_amp_gtag_opt to make it available for developers to modify the $config options https://github.com/google/site-kit-wp/blob/4c691659af7d975205be2957e2e7d36b26f9e8e7/includes/Modules/Analytics.php#L317

  • Add @see annotation in the doc-block of the filter pointing to https://developers.google.com/gtagjs/devguide/amp

  • After running the filter ensure $config['vars']['gtag_id'] exists and set it to the original $tracking_id

Changelog entry

  • Allow filtering the Google Analytics gtag configuration options for both AMP and non-AMP context.

bjackson27 avatar Jun 25 '19 13:06 bjackson27

@lucymtc The implementation brief for the AMP implementation misses a point (apologies if that didn't become clear from the acceptance criteria):

  • Not just the vars.config property in the object should be filtered, but the entire object needs to be filtered. The reason is that there are other top-level properties than vars that developers may want to update.
  • After running the filter, it has to be ensured that vars.gtag_id still exists and is set to the original tracking ID.

felixarntz avatar Aug 05 '19 06:08 felixarntz

Implementation brief looks good!

felixarntz avatar Aug 05 '19 12:08 felixarntz

QA is good!

felixarntz avatar Aug 13 '19 12:08 felixarntz