I have this code for many years, implementing TCFv2 cookie consent with Google Funding Choices.
window.googlefc.callbackQueue.push({
'CONSENT_DATA_READY': function () {
/* __tcfapi is undefined!! */
return __tcfapi('addEventListener', 2, function (tcData, success) {
if (success
&& tcData.gdprApplies
&& (tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete')
&& tcData.purpose.consents[1]) {
...
}
});
}
});
It works 99.99% of the time, it has appeared so.
However, today, one of my Chrome profiles seem to have got "broken", in that whenever this CONSENT_DATA_READY
event is triggered, __tcfapi is not defined
.
I tried a number of things, like making sure all extensions are disabled, close Chrome and re-open it, clear just my domain's cookies, etc, but nothing worked. All other Chrome profiles were working well all the time.
I compared the "Sources" tab in DevTools between two Chrome profiles (on the same webpage), and the one working well had a few more scripts loaded and iframes loaded (TCF-specific iframes).
Only when I cleared all the cookies (including the "google.com" scoped cookies), this issue got fixed.
--
I've just released a temporary piece of code, that checks if __tcfapi
is undefined in that spot and reports that to the server (this user data will be fully erased as soon as this test is complete), and I see that a small subset of my users is having this issue right now.
EDIT 18 Dec - 181 distinct European users reported so far.
--
I'm not able to find any solution by doing some research. I found someone on Reddit (in the comments) having the same issue as me, and they "resolved" by just removing the event. Other places that report issues with __tcfapi
seem to be a slightly different error, like __tcfapi is not a function
, which is not the issue I'm having.
--
This looks like it's a bug from Google Funding Choices, but does anyone have any idea how to "auto-fix" this or what can I do so that these users will stop getting this error and proceed as expected?
NB: This is a complete re-edit to reflect the discussion with the questioner.
Some thoughts.
On Error 2.1a
I first suspected that your problem may correspond to Error 2.1a, which is also indicated by the discussion in the GFC community thread you pointed at. The suggested official solution would be to check whether
getTCData
returnsTCData.eventStatus = 'tcloaded'
first.That may work in other cases, however you pointed out -- and added corresponding code -- that you already check on
tcloaded
but the problem of an undefined__tcfapi
seems to occur even before that flag is even created.Another look on the problem's origin
The GFC community thread of 2020, the TCFv2 standardization history and the circumstance that the thread has been closed indicate that the problem mainly existed before the final implementation of TFCv2 in Google Funding Choices. That corresponds to the fact that the described behavior infringes the TCFv2 Specification in the following:
However, it's not unreasonable that there are still some older implementations out there in the wild which may cause this problem at some clients.
Interestingly enough, you observed that on your side one of your Chrome profiles got "broken" in the described way and only the clearing of all cookies, incl. the "google.com" scoped ones, fixed the issue.
And now?
At first it would be interesting to check for
tcfPolicyVersion
used by the problematic clients, andIt also can't hurt to take a look on the official site on Publisher integration with the IAB TCF v2.0 in case some useful gem is hidden which we currently overlook.
On the other hand it could well be that this -- probably rare -- problem will resolve by itself over time when
It seems reasonable to assume, that your current patch -- to check whether
__tcfapi
is undefined -- may be indeed a (fairish) suitable fix, at least for now.