attempting to report data to a tracker before its configured has started producing an error.
i have some plugins that report based on a GA tracker ID, i also install that tracker on my site. the problem is that if any plugin produces an event before the tracker is configured, gtag.js adds a separate https://www.googletagmanager.com/gtag/destination?id=G-XXX tag to the page, and then when the actual tracker config gets called, the script https://www.googletagmanager.com/gtag/js?id=G-XXXX which gets added then produces an error: Duplicate container installation abandoned: G-XXX and does nothing.
i’m pretty sure this was not causing an error a few weeks ago.
i have tried both settings for the “Additional Settings” > “ignore duplicate instances of on-page configuration (recommended)” option, it doesn’t seem to be related to this issue.
this code produces the issue:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
const trackerId = 'G-XXXXX'
gtag('event', 'test', {send_to: trackerId})
gtag('config', trackerId);
</script>
<script async src="https://www.googletagmanager.com/gtag.js"></script>
(in real life i’m not controlling where the events are coming from, and the config call is being done in GTM. the code does occasionally pass, i think there is a race condition having to do with the injected scripts loading)
i’m going to try to organize it so the plugins are only loaded after the tracker is configured, but i’m pretty sure this used to work, and it seems really problematic that it happens like this. for instance one of the plugins causing the issue is google optimize, which is installed according to the instructions.
is there something i can do to make it just reconfigure the tracker and not error when config is called?