Sentry #
Integrating with Sentry was a breeze. I’ll probably use it in a future project but it was more focused on crash analytics and tracking error issues. I’m looking for user analytics so I was just looking in the wrong place.
GameAnalytics #
Their Godot SDK requires recompiling Godot from source. They must have a good reason for not just using an add-on but it was enough to get me to try another solution first.
PostHog #
Somebody on Reddit recommended PostHog. A couple people have written their own integrations:
Been a few years since they were updated and I needed to tweak it to get it working (the capture URL has changed) but coelhucas/godot-posthog saved me some time.
Storing the API Key #
The API key is stored in the Godot runtime which can be decompiled. It’s not safe there but there’s not much I can do about that. PostHog documentation confirms that the API key is (relatively) safe to have out in the open. At most, a malicious user will be able to send fake telemetry. There’s no danger of them extracting data and certainly not any private data using that key. Good.
But I still don’t want to commit the key to my repo. I don’t want to make it that easy.
The strategy I’m working with is to set the API key in override.cfg and add that file to .gitignore. That file overrides project settings so in the code I can use:
var key: String = ProjectSettings.get_setting_with_override("global/api_key")
There is another method ProjectSettings.get_setting() but that won’t include overridden values so don’t use that. That was a gotcha for me.
While troubleshooting that, PostHog directed me to a useful tool for troubleshooting calls like that: https://webhook.site
…
Tested on Itch.io and the values from override.cfg are not being used when the game is run on the web. I tried placing override.cfg in my web export folder, since apparently that works when running the game as a binary. Doesn’t work. I get the value from project.godot instead.
I can’t find a way to pass information to Godot during compile time either so looks like I’m gonna go ahead and embed that key in my project settings and then commit the settings to my repo after all.
If you know a better way, let me know!