Insert HTML comments for each module/product snippet
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.
- Above:
- 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 theanalytics-4module) - 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
* AMPannotation. - 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
rendermethods:Modules/Adsense/Web_TagModules/Adsense/AMP_Tag- Note that the comments all need to be added to the
amp_content_add_auto_adsandset_story_ad_slot_idmethods
- Note that the comments all need to be added to the
- For Analytics AMP
rendermethods:Modules/Analytics/AMP_Tag
- For Tag Manager
rendermethods:Modules/Tag_Manager/AMP_TagModules/Tag_Manager/Web_Tag
- For Analytics and Analytics 4 use the
script_loader_tagfilter to add the comments:Modules/Analytics/Web_TagModules/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.
@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)
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.
Thanks @eugene-manuilov, I have updated the IB 👍
@Hazlitte we also need to mention the Analytics-4 module.
👍
IB :heavy_check_mark:
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.
@kuasha420 would you please add a QA brief?
@aaemnnosttv Done. Should it be a QA:Eng as well?
@kuasha420 thanks! I don't think it's needed but we can always add it later if we feel it is 👍
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 as per our slack discussion with @aaemnnosttv, can you process this and create a separate issue accordingly.
Cheers.
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.
