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

Insert HTML comments for each module/product snippet

Open jamesozzie opened this issue 6 years ago • 13 comments

Feature Description

For the different snippets place via Site Kit it may be useful to insert a comment such as inserted via Site Kit.

The AdSense module already provides a useful hint in the form of the below: tag_partner: "site_kit" 

While there are additional hints of Site Kit placements more obvious comments may assist in troubleshooting issues, in particular for Analytics and Tag Manager users.


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

Acceptance criteria

  • All snippets which Site Kit places for Google services should be annotated with surrounding HTML comments:
    • Above: Google xyz snippet added by Site Kit
    • Below: End Google xyz snippet added by Site Kit
    • See below for the different "xyz" permutations.
  • For AdSense (web and AMP): AdSense, AdSense AMP
  • For Analytics (web and AMP, plus opt-out): Analytics, Analytics AMP, Analytics opt-out, Analytics AMP opt-out (all of these annotations should also be used for the respective GA4 snippets in the analytics-4 module)
  • For Tag Manager (web and AMP): Tag Manager, Tag Manager AMP
  • Anywhere a snippet is rendered for (AMP) Stories, it should also use the regular * AMP annotation.
  • The comments should always be separated from the actual snippet through a line break, i.e. they should not appear in the same line.

Implementation Brief

As per the AC add HTML comments above and below the placement of each tag snippet. Ensure the comments are separated from the tag snippet using line breaks. The comments are:

  • Above: Google xyz snippet added by Site Kit
  • Below: End Google xyz snippet added by Site Kit

In each case replace xyz with the relevant text in the AC.

  • For Adsense add the comments to the output of the tag snippets in the render methods:
    • Modules/Adsense/Web_Tag
    • Modules/Adsense/AMP_Tag
      • Note that the comments all need to be added to the amp_content_add_auto_ads and set_story_ad_slot_id methods
  • For Analytics AMP render methods:
    • Modules/Analytics/AMP_Tag
  • For Tag Manager render methods:
    • Modules/Tag_Manager/AMP_Tag
    • Modules/Tag_Manager/Web_Tag
  • For Analytics and Analytics 4 use the script_loader_tag filter to add the comments:
    • Modules/Analytics/Web_Tag
    • Modules/Analytics_4/Web_Tag

QA Brief

  • As per the AC, all inserted snippets by Site Kit will have surrounding HTML comments.
  • You will need to enable all the modules to test every snippets.
  • For Opt Out snippets, you'll need to have Analytics Opt Out Enabled
  • Please check for both logged in and not logged in state!
  • Use View Source to inspect the source code and feel free to use "Ctrl+F / Cmd+F" to find the relevant parts of the source code. ie. 'snippet added by Site Kit'

Changelog entry

  • Add surrounding comments to all HTML tags output by Site Kit modules.

jamesozzie avatar May 05 '20 15:05 jamesozzie

@felixarntz @jamesozzie I have added an IB for this. Note that render methods are not being used to output all tag snippets, in some cases wp_enqueue_script is being used. (as noted in the IB)

Hazlitte avatar Jun 04 '21 13:06 Hazlitte

Note that wp_enqueue_script is used instead of render methods so the comments cannot be added for: Modules/Analytics/Web_tag Modules/Analytics_4/Web_tag

@Hazlitte there is the script_loader_tag filter that we can use to add comments to enqueued scripts.

eugene-manuilov avatar Jul 12 '21 15:07 eugene-manuilov

Thanks @eugene-manuilov, I have updated the IB 👍

Hazlitte avatar Jul 13 '21 12:07 Hazlitte

@Hazlitte we also need to mention the Analytics-4 module.

eugene-manuilov avatar Jul 13 '21 13:07 eugene-manuilov

👍

Hazlitte avatar Jul 13 '21 13:07 Hazlitte

IB :heavy_check_mark:

eugene-manuilov avatar Jul 13 '21 17:07 eugene-manuilov

Tagging this as a good first issue—the approach is straightforward though to test the output it will require setting up a site with AdSense, Analytics, Google Analytics 4, and Tag Manager. AdSense should be done with the tester plugin.

tofumatt avatar Aug 19 '21 13:08 tofumatt

@kuasha420 would you please add a QA brief?

aaemnnosttv avatar Aug 31 '21 08:08 aaemnnosttv

@aaemnnosttv Done. Should it be a QA:Eng as well?

kuasha420 avatar Aug 31 '21 08:08 kuasha420

@kuasha420 thanks! I don't think it's needed but we can always add it later if we feel it is 👍

aaemnnosttv avatar Aug 31 '21 14:08 aaemnnosttv

QA Update: ❌

@kuasha420 @aaemnnosttv An observation: Exclude from Analytics is enabled, so when I look at the source code in AMP I was expecting to see the opt-out snippet but I don't. All I see are is the HTML code <!-- Google Analytics AMP opt-out snippet added by Site Kit -->``<!-- End Google Analytics AMP opt-out snippet added by Site Kit --> The snippet does appear for non AMP.

wpdarren avatar Sep 02 '21 13:09 wpdarren

@wpdarren as per our slack discussion with @aaemnnosttv, can you process this and create a separate issue accordingly.

Cheers.

kuasha420 avatar Sep 02 '21 16:09 kuasha420

QA Update: ✅

Verified:

All snippets which Site Kit places for Google services have annotated with surrounding HTML comments:

  • For AdSense (web and AMP): AdSense, AdSense AMP

  • For Analytics (web and AMP, plus opt-out): Analytics, Analytics AMP, Analytics opt-out, Analytics AMP opt-out Screenshot

  • For Tag Manager (web and AMP): Tag Manager, Tag Manager AMP Screenshot

  • Tested the HTML comments when logged in and out.

  • The comments are separated from the actual snippet through a line break, i.e. they do not appear in the same line.

image

wpdarren avatar Sep 03 '21 12:09 wpdarren