How to add Google Analytics etc. for web site visitor traffic analysis?

What are best practices for adding Google Analytics etc. for an App?

Hi!

When it comes to Google Analytics, you may add the Google Analytics Tracking ID from Appfarm Create → Environments Config.

Info about this is found here. Once you add an ID (“UA-…”), the necessary scripts will be added to your apps, and page views will be automatically tracked. As with all client-side analytics, any ad-blockers or browser settings that prevent tracking may affect your reporting.

Note that this is only for Universal Analytics properties. Google Analytics 4 is not currently supported, but a challenge (change request) is registered on that.

If you want to log Events from your Apps (or custom Pageviews), you may use action node “Google Analytics Event” to send a specific Categories/Action (and optionally Labels or Values) to Google Analytics.

2 Likes

What if we want to track traffic using other tools like Hotjar, Matomo, Smartlook, Clicky, Mixpanel etc. These usually require that we add a custom javascript tag. What are the best-practices for adding such a script tag?

Hi! That is supported by adding the external javascript in the"Custom header tags" section of either Environment Config or App Settings. If the script should only be available in 1 app - add it to App Settings

Once added, you may trigger methods of that javascript using the Run Code action node, or inside the Coded Component ui component.

Note that if you encounter some errors refering to “content security policy” when running the script (e.g. refusing to connect to some external url), you might need to add a url hostname or two in the Content Security section of Environment Config.

1 Like

Under GDPR it is required to only load certain cookies after the user has consented to the cookies. How can this be accomplished in appfarm? I can´t see any way of adding a condition in the custom header tags section.

@kristian or anyone ?

I’m not an expert in these matters, but here is my personal understanding.

I guess you are refering to when you have added GA4 Analytics script to your App according to these steps:

And, as you say, these scripts are loaded when the App is loaded.

I guess if you have added these scripts to an “anonymous landing page” you will need to implement some cookie concent when the page is loaded. But in my impression, adding these scripts to the App alone is not logging anything. The logging is done using the Run Code action node, as described here, and you may choose to to this after the user has consented.