Implement existing snippet detection for Tag Manager #433
Comments
This is out of scope for this issue, we also don't consider multiple in the other modules. Worth discussing for the future though as a general enhancement.
You don't necessarily need to add this in detail as part of the IB, but just to flag it, it needs careful investigation in which ways Tag Manager can be included in a page, including AMP and non-AMP versions. The regexes used need to provide sufficient coverage of different alternatives. At least a note on this might be good to have here. |
|
I've updated the IB to remove the multiple properties part and added the note about being diligent about checking for different Tag Manager include snippets in our checks. |
|
IB |
"User" or "Admin" permissions are at the account level. Containers can have individual permissions apart from that. Do we want to specifically check that the user has Admin level permissions on the container's account or should we instead check for "full" permissions on the container itself (i.e "publish")? Note: we can check this using the |
|
@aaemnnosttv agreed - better to be more granular here and focus on individual container permissions rather than account-level permissions. |
|
Thanks @marrrmarrr this is actually fairly straightforward as Admins inherit the |
|
@felixarntz @marrrmarrr it seems that much of the acceptance criteria has been borrowed from Analytics but I think there are some important differences to consider here which may not have been evident before. Perhaps the most fundamental difference is that Analytics also brings data into WordPress, but Tag Manager is currently a simple client-side only integration (outputting the snippet) with no data in WordPress other than account and container names to choose from. In the case of an existing tag, I don't think we necessarily need to block the user from completing setup or check their permissions. Compared to Analytics, all we're doing is outputting the script on the front end which loads tags from the container. I don't think there is any reason why we can't output more than one (not the case of course with Analytics). Analytics has the concept (and setting for) whether or not to output the snippet because data can still be shown in the plugin while something else is responsible for outputting the tag which generates that data. This is not the case with Tag Manager as its sole responsibility is outputting a script to load the container. In this case, it doesn't make sense to force the setup to use the account and container IDs from an existing tag because it would simply result in duplicate tags on the front. For these reasons I think that permissions/access/messaging around existing tags could be greatly simplified/removed with more of a focus on making the user aware, and only block them (perhaps) from setting the site up with the same tag as an existing tag to prevent duplicates. |
|
@aaemnnosttv Good point. I agree we need to ensure there are no duplicate tags in the frontend. However, similar to Analytics we also need to ensure there are not two Tag Manager tags in the frontend, that's why we need this check for existing tag. In Analytics it's actually the same, it doesn't technically hurt to have more than one tracking snippet, it would just track the same thing to different Analytics properties, and only the data from the one active in Site Kit would show in the plugin. However, we were advised by the Analytics team that this should be avoided. Summarizing, I think we should for now block users without access the same way we do for Analytics to prevent multiple Tag Manager tags in the frontend. In the case of an existing tag, we then need to set a flag in the database that ensures our own snippet is not printed. I'd suggest just using another |
I'm not entirely sure what you mean here. What does the user's access have to do with preventing multiple tags? If we want to prevent multiple then completing setup shouldn't be possible if there is an existing tag.
Why allow the user to complete the setup if it won't output the tag? This sounds like a confusing experience for the user. If we were to set I think we should simply block setup from completing if there is any existing tag if we don't want to allow for multiple. |
Yes, but we'd only want to block if the user doesn't have access. If the user has access, we can consider Tag Manager active, force-set the account that has access to the existing tag, and just not print it ourselves (hence the
It's the same for Analytics. We allow users to complete the setup if there is an existing tag they have access to. Under those circumstances, we force-choose that property and don't place the tag ourselves. I think for GTM we can do the same. When you access the module settings, we should re-check for the existing tag, and if there's none anymore, we can silently set |
|
@aaemnnosttv
The reasoning is the following: We'll expand what the GTM module does, and even if it technically does nothing at this point, we should allow the user to complete the setup. Note that we'll also want a setting for whether the snippet is placed, that is initially auto-determined, but the user can adjust it in settings afterwards (again similar to Analytics). I've updated the ACs, sending this back to IB now so that this part can be added. |
|
IB |
|
Tested Verified snippet detection occurred: Confirmed cancel button functions. Verified permissions message displays properly when user doesn't have the correct permissions: Picky but @tofumatt, should the above 'Cancel' button be labeled 'Back'? Passed QA |
This is consistent with the other setup modules. Also I think it may not be possible to have different wording for the cancel button currently due the way the setup module components are composed. |
|
It's definitely not nice UX though, agreed. We should fix those en-masse—could you create an issue for any modules that should have that wording changed @cole10up? |
|
LGTM. |
|
@tofumatt @marrrmarrr I've created this ticket to adjust verbiage where user's presented an expected error message: #1045 I'm unsure of other cases, please advise. |






Feature Description
We currently detect existing snippets for Analytics and AdSense. This detection should happen for Tag Manager as well, and cover non-AMP as well as AMP.
If an existing tag is found, it should work like in Analytics: If the user has access to that very container, it should be forced. If not, the user should be blocked from proceeding. In both cases, the user should be informed about the existing tag and that it comes from another code source.
In other words, this issue will also include a couple of UI changes/requirements.
This was originally reported as part of #413.
This issue is blocked by #83 and #432, but theoretically implementation can at least start before these are fully completed.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
useSnippet); in GTM setup this should not be displayed and instead automatically determined:Case 1: the account has access to the container:
Case 2: the account doesn't have access to the container:
Implementation Brief
getExistingTagto support Tag Manager snippet pattern matching forGTM-*container public IDTag_Managertag output for$_GET[tagverify]requests (see Analytics and AdSense modules)getExistingTagThe user must have
publishpermission for the individual containerSee messaging in AC
Tag_Manager::create_container()(#361)useSnippetsetting based on presence of existing tag (if existing tag,useSnippet = false, otherwise default totrue)useSnippetsetting toggle (most of this can be borrowed from Analytics)useSnippettotrueif the key does not exist yetChangelog entry
The text was updated successfully, but these errors were encountered: