With Google Analytics 4 [GA4] it's possible to add custom user properties to each event.
- Optional: Add any custom user properties that you'd like to configure in User Properties.
This is explained further in [GA4] About event parameters.
Now, this code works fine and the value of test is appended to the initial page_view and other following events:
gtag('config', 'G-1234567890', {
test: false
});
Our site is a single page application (SPA) and at some point we want to update the parameter test.
The mentioned docs and also the Global site tag API reference set say, these parameters can be updated at any time. I found these two versions:
gtag('set', 'user_properties', {test: true});
gtag('set', {test: true});
Unfortunately, both won't work. I can get the updated parameter successfully using get:
gtag('get', 'G-1234567890', 'test', (test) => {
console.log(test); // true
});
But the value is never updated for any subsequent request to Google Analytics and test: false is tracked all the time.
What are we doing wrong?