The existing tag detection for Google Analytics is currently too loose in its matching where it may match tags of other services used in the same place in a script, such as AdWords.
E.g. #732
<!-- Global site tag (gtag.js) - Google Ads: CONVERSION_ID -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-CONVERSION_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config','AW-CONVERSION_ID');
</script>
Source: https://support.google.com/google-ads/answer/7548399?hl=en
This script matches as an existing Analytics tag of AW-CONVERSION_ID (see below).
AW-..., unable to proceed
_Do not alter or remove anything below. The following sections will be managed by moderators only._
UA-GTM- (implemented in #433)ca-pub- IB LGTM!
PS: the snippet detection has be quite fragile historically and @adamsilverstein has done quite a bit of work on it originally if I recall well.
@ThierryA @felixarntz while working on this one, I realized that the fetch request used for detecting tags was making the request with the current logged in state of the current user which is the default for fetch as long as the URL is same-origin. This will cause the tag detection to fail in many cases as many Analytics plugins don't output the tracking code for logged in users, or users of a particular role.
This is a simple fix that I've included in the PR so that this request is always made without authentication.
This passes QA in my testing, moving to Approval.
<script>
(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-12345-1', 'auto');ga('send', 'pageview');
</script>
One possible unrelated issue I noticed while testing this is that there no existing tag detection for Tag Manager setup. Speaking to @aaemnnosttv there is an existing issue to cover adding this.
Most helpful comment
@ThierryA @felixarntz while working on this one, I realized that the fetch request used for detecting tags was making the request with the current logged in state of the current user which is the default for
fetchas long as the URL issame-origin. This will cause the tag detection to fail in many cases as many Analytics plugins don't output the tracking code for logged in users, or users of a particular role.This is a simple fix that I've included in the PR so that this request is always made without authentication.