The config parameter name for cookie domain has changed. Previously, it was cookieDomain
(see old UA documentation). Now, it is cookie_domain
(see current GA4 documentation).
Other parameter names have changed as well.
It is not possible to add a working cookie domain to GA4 using the "create only fields" field because the acceptable parameters are hardcoded in googleanalytics.admin.inc:
function _googleanalytics_validate_create_field_name($name) {
// List of supported field names:
// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create
$create_only_fields = array(
'allowAnchor',
'alwaysSendReferrer',
'clientId',
'cookieName',
'cookieDomain',
'cookieExpires',
'legacyCookieDomain',
'legacyHistoryImport',
'sampleRate',
'siteSpeedSampleRate',
'storage',
'useAmpClientId',
);
If you put in one of the allowed names with a value, it is output in the config function. Here's an obfuscated example from a live site that has both a UA and a GA4 ID configured:
gtag("config", "UA-12345678-1", {"groups":"default","cookieDomain":"whatever.example.com","anonymize_ip":true});
gtag("config", "G-123ABC456", {"groups":"default","cookieDomain":"whatever.example.com","anonymize_ip":true});;
However, "create only fields" are no longer a thing on GA4. They are just config parameters set with the config function, not the old create function. The field label and help text are confusing in this context. The current setup is only allowing UA create function parameters, but is adding them using the config function, which most likely means they are not working for either UA (where the create function is what's needed) or GA4 (where the parameters have different names).
Also in GA4 there doesn't look like there's a list of allowed config parameters that could be hardcoded into the module. So allowing arbitrary name/value pairs might be the way to go.
On a site that's served from a subdomain (for example whatever.example.com):
cookie_domain|whatever.example.com
cookieDomain|whatever.example.com
.Given that UA is being sunset in a month, and GA4 does not seem to have a limited list of available config parameters, would the best thing to do be to patch for GA4 (removing the hardcoded list and deciding whether to put in any validation) and roll a release after July 1? If the current setup isn't even working for UA, maybe there's no backwards compatibility we need to preserve?
Patch and test.
Update field label and help text to accurately convey what this field is (config parameters).
N/A
N/A
Active
2.0
Code