Search code examples
google-chromegoogle-analytics-4gtag.js

ga4 gtag.js started showing error in Chrome


today I noticed that in Chrome gtag/js?id=... started giving an error:

Uncaught (in promise) TypeError: Failed to execute 'getValue' on 'CookieDeprecationLabel': 

in gtag.js, the error occurs here:

try {
    tc.cookieDeprecationLabel ? (a("pending"),
    (0,
    tc.cookieDeprecationLabel.getValue)().then(a)) : a("noapi") // error here
} catch (b) {
    a("error")
}

UPDATE: I hit F12 in this site (stackoverflow) and noticed that the error is present here as well (for me at least)


Solution

  • This look related to third-party cookie restrictions

    Like explained on Chrome facilited testing, third-party cookie restrictions will be deployed as a preview for some chrome user.

    It's looks like google tag manager is using the cookieDeprecationLabel JavaScript API in order to determine if the restriction is enabled.

    try {
        tc.cookieDeprecationLabel ? (a("pending"),
        (0,
        tc.cookieDeprecationLabel.getValue)().then(a)) : a("noapi")
    } catch (b) {
        a("error")
    }
    

    When the cookieDeprecationLabel JavaScript API is present google tag manager try to access to it's value which throw an TypeError: Illegal invocation.

    As told by @DarkBee an issue has already been opened on tagmanager's support.

    If as a developer, you doesn't have the issue but want to check if your app is broken when it happen (like me) you can activate it following this google instructions Third party cookie Phase Out Facilitated Testing

    [EDIT] August 12, 2024

    As told by @bjarne-gerhardt-pedersen Here the issue seems to have been fixed by the GTM team.