Send event parameters with every event and multiple tags in Google Analytics 4

gtag

There are some event parameters that are useful to send with every event. Google has a helpful guide here which even covers the case where you have multiple tags (I'm running GA4 and UA during the migration and this isn't unusual). You're supposed to call gtag set before calling config on each tag. This isn't working for me though, I see nothing coming through in the debug view.

Calling set before config works fine for user properties (my journey of discovery yesterday) but unless I was doing something stupid that I haven't seen yet no dice for event parameters. The code above uses the config method of initialization with a shared object to prevent duplicating code. This seems to work fine.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Send event parameters with every event and multiple tags in Google Analytics 4 #code #ga4 How to send common event parameters with every event in Google Analytics 4 )

User scoped custom dimensions in Google Analytics 4 using gtag

A user parameter in the GA4 debug view

Given that everything in Google Analytics 4 is an event I expected user scoped custom dimensions to be a regular event parameter as well. They're not. And most of the documentation both from Google and others talks about Google Tag Manager which doesn't help if you're just using gtag. It's not that hard to implement, but figuring out all the pieces was way harder than it should be. I hope this helps the next person...

To create a user scoped custom dimension you need a user property. This is different from an event property. In gtag you need to call set on user_properties with an object containing the user properties to set like this:

If you want the user property on the hit sent with page load do this right before the config call when loading your gtag (you can do it as part of the config call if you're just setting up one tag, or as above before the config call which is helpful if using more than one tag). If you don't know the value of the user property at page load time you can also set it and then send an event.

From the client you can inspect the beacon sent to GA4 for an event, for example:

Event parameters get a prefix of ep or epn. In this case I'm using a parameter rc_score set to 0.9 which appears in the beacon as epn.rc_score=0.9. GA auto-detects numeric values and uses epn for these. The user parameter gets a up prefix and in this case is up.user_quality=low. (In this specific case I'm sending a recapture score as both a custom metric and a user scoped dimension so I can segment out high and low quality users, at least from the perspective of recapture).

More visually you can use the debug view in the configure section of GA4 (why there are settings in the reporting interface as well as the settings interface I have no idea). To use this pass { 'debug_mode':true } to your gtag config call. To confirm that you're getting user properties look for an orange icon in the timeline (see screenshot at the top of this post). There is also a helpful user properties active now box at the bottom right of this screen.

Once you have this working you still need to wire it up in GA4. Wait 24 hours... then go to Configure -> Custom definitions. Add a new custom dimension, make sure you pick user scoped and you should then be able to select the user property to use to populate the dimension.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: User scoped custom dimensions in Google Analytics 4 using gtag #code #ga4 Step by step guide for sending user scoped custom dimensions to Google Analytics 4 via gtag. )

Fortune Cookies for Android 1.30

Fortune Cookies for Android 1.30

I've just released Fortune Cookies for Android 1.30. The last update was in... 2013... it turns out the Android ecosystem has moved on a bit since then and it wasn't even in the Play Store any more as a result. This update has a nice modern theme but is otherwise just an Android version of the classic UNIX fortune command. The database of fortunes is ancient and just running this might get you canceled / fired / etc so use with due caution. If you have this installed it will update as soon as the release is approved.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Fortune Cookies for Android 1.30 #code #fortune #software UNIX style fortune cookies on Android (updated for Android 12) )

Catfood Earth 4.30

By Robert Ellison. Updated on Sunday, October 23, 2022.

Catfood Earth Satellite Composite Image of Earth including Volcanoes and Earthquakes

Catfood Earth 4.30 is available to download.

This update fixes a couple of problems with the screensaver. It now has improved support for multiple monitors (the image will repeat rather than stretch). There was a problem with the screensaver not starting in some cases. This should now be fixed. After upgrading to 4.30 please find and run the 'Catfood Earth Screensaver Settings' shortcut to configure the screensaver.

4.30 also includes version 2022d of the time zone database.

Add your comment...

Related Posts

(All Code Posts)

Autumnal Equinox 2022

Catfood Earth render of the exact moment of the Autumnal (Fall) Equinox 2022.

Autumn (or Fall) starts now (23 September 2022, 01:04 UTC) in the Northern Hemisphere, Spring if you happen to be south of the Equator. Rendered in Catfood Earth.

Add your comment...

Related Posts

(All Code Posts)

Photo Sorter 1.20

By Robert Ellison. Updated on Sunday, October 2, 2022.

Photo Sorter 1.20

Photo Sorter has been updated to handle some duplicates I've been developing in Google Photos. These are pretty specific rules but might be helpful if you are trying to maintain a local archive from Google Photos via Google Takeout. You can get the latest binary and source from github (or fork away if it's not quite what you need).

The first change is that Photo Sorter now checks for duplicates in the source folder as well as the destination. If two source files have the same date taken and the same filename then the larger file is chosen as the winner and the smaller file is deleted. The filename check ignores anything in parentheses, so 123.jpg is considered to be the same filename as 123(1).jpg. This helps alleviate a fun bug where Google Photos will export via the API a different file that was originally uploaded. I've stopped using the Google Photos API for this reason, and because it will under no circumstances allow you to download a video that is the same quality as the original upload. Crazy edge case Google. Happily Google Takeout still works so I'm stuck doing it slowly and wastefully.

The second change is that if a source duplicate is found using the rules above then it will also be deleted from the destination folder (in order to be replaced by the presumed better version of itself).

Photo Sorter copies some folder full of photos and movies to a different folder with a clean structure and some de-duplication. It's been keeping me sane since 2018.

Add your comment...

Related Posts

(All Code Posts)

Catfood WebCamSaver 3.29.0002

By Robert Ellison. Updated on Saturday, September 24, 2022.

Catfood WebCamSaver 3.29.0002

Catfood WebCamSaver 3.29 is now available to download.

This release updates the webcam list and includes a selection of new webcams provided by a long-time user.

Add your comment...

Related Posts

(All Code Posts)

Summer Solstice 2022

Summer Solstice 2022

Summer starts right now (09:14 UTC June 21 2022) in the northern hemisphere, winter for those with latitude signum differences. Rendered in Catfood Earth.

Add your comment...

Related Posts

(All Code Posts)

Outlook/Office iCal feed 400 bad request error with C# WebClient

By Robert Ellison. Updated on Tuesday, June 21, 2022.

400

Just in case it helps someone else I was able to fetch an Outlook iCal feed using C#'s WebClient for years until it stopped working in June, 2022 with a 400 / bad request error. I was downloading a set of calendars and the fix was just to use a new WebClient for each calendar so it must be some kind of state thing in WebClient.

To regain around 1% of sanity I have a task that pulls the various calendars that life throws at me and combines them into a single, de-duplicated calendar. The Google Calendar on my phone is gorgeous as a result. My primary calendar is orange and then all of the miscellanea are teal and unique. It would be great if Google Calendar could do this without help, but it was worth the effort not to have some random soccer match repeated five times in different colors.

Last week one calendar, an Outlook feed, started failing with 400 bad request.

Naturally I assumed that the server had started to suddenly care about some header or other and I started playing around with setting User-Agent and various Accept headers without any luck. To make debugging slightly easier I moved the Outlook calendar out of a loop (where I was iterating through a list of iCal feeds that I need to be aware of) and then it magically started working. The magic in this case must be a fresh WebClient and so the fix was to use a new WebClient for each calendar instead of reusing a single instance. It looks like WebClient is deprecated in .NET 6 and one is supposed to start using HttpClient instead so that's probably another fix but not one I'm going to wrestle with today.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Outlook/Office iCal feed 400 bad request error with C# WebClient #code #c# #outlook How to fix a 400 / bad request error with the C# WebClient when downloading an Office iCal feed. )

Catfood WebCamSaver 3.28

By Robert Ellison. Updated on Friday, June 24, 2022.

Catfood WebCamSaver 3.28

Catfood WebCamSaver 3.28 is available to download.

This release updates the webcam list.

Add your comment...

Related Posts

(All Code Posts)