how to use web and server tracking for GA4 using GTM - google-tag-manager

I'm using GTM to install the two tags of GA4 (Web and server), the problem is how to eliminate the duplicated events coming from the two sources (Web and server), I used an Event_id as an event parameter but I still see the duplicate event in GA4 with the same event id !!

Related

How to include anonymous page views when using GA4 UI / Data Studio Connector and Cookiebot?

We are using UA and GA4 via Google Tag Manager and we have Cookiebot managing user's consent. We are also having GA4 BigQuery output enabled.
We would like to count anonymous page views when users didn't consent to cookies.
i.e. the expectation is that we can count page views and potentially other events, but it wouldn't be connected to a user's session or contain personal identifiable information.
(the assumption is that this should be GDPR compliant)
However, using specific page URLs, I tried to test the behaviour and I observed that no event was recorded before accepting cookies.
In our BigQuery data, we can also see see some events that do not have a ga4_session_id.
(The assumption was that those people didn't consent to cookies, but this might be wrong)
When comparing the numbers with the GA4 UI or Data Studio Connector, it appears that the events without a session id are not included in the GA4 UI / Connector page view numbers.
i.e. even if BigQuery data without session id were for people not accepting cookies, those wouldn't be counted by the GA4 UI or Data Studio Connector.
How can I can I count anonymous page views using the GA4 UI and Google Data Studio Connector?
(I've posted the same question to Analytics Help forum but didn't get a response)

User properties are not save between different sessions via Google Analytics 4 (events are sent with GTM server)

I implemented on my website GTM client, GTM server and Google Analytics 4.
Now I send events from GTM client to the GTM server from there it moves to the Google Analytics 4.
The event that is sent from the GTM client to the server contains event params and user properties.
All the user properties are sent to the Google Analytics 4.
Let me explain the situation I ran into.
Let's say I'm sending an event from the GTM server to google analytics, the event contains user properties.
Those user properties are user scoped and should be remain the same unless I change them again.
after a couple of hours after the current session ends I create another session (with the same user), however the user properties are not save although I do not run the over.
Also I saw that in the event data in the GTM server I get the same client_id and the same x-ga-js_client_id. (in the different sessions)
The implementation of the GTM server is by is by check the Send to server container checkbox via "Google Analytics: GA4 Configuration"
Expected Behavior: I would like that the user properties will be saved between different sessions in Google Analytics 4 for the same user while the events are sent via GTM server
Steps to Reproduce:
creating "Google Analytics: GA4 Configuration" tag in GTM client
creating tag in GTM client that has this Google Analytics: GA4 tag
set this tag with some user properties
creating second tag in GTM client that has this Google Analytics: GA4 tag with no user properties
create a session and send the first tag to GTM server
wait few hours till session end
create a session and send the second tag to GTM server

Users not being tracked in Google Analytics 4 using Google Tag Manager Server

I am trying to send event data to Google Analytics 4 through a Google Tag Manager Server container. This setup will later be used to track an app for which we will not be using the Google SDK. However whatever I try, I can't seem to record users within GA4, even though the events are recorded.
Currently, I send an HTTP POST request from Postman to our Google Tag Manager Server container, which is captured by a custom Client and is processed by the official GA4 tag. Within the GA4 tag, I map the original event data to the event data needed by GA4. The request that is sent is shown below:
Also, GTM shows a 204 response code.
When the GA4 tag sends the request to GA4, I do see the event coming in, but no user is recorded:
Which parameters am I missing that are required?
(Yes, I know that there are dedicated App streams within GA4, but you have to connect your account to Firebase, which is exactly what we do not want for our setup. Therefore, I set up a web stream.)

Google analytics - allowed hosts

I'm seeing entries in my analytics data for pages that no longer exist.
This could be developers looking at legacy versions of a site, it could also be triggered by something like wayback machine.
Is there a way to either identify what hosts an analytics tracking pixel is being triggered on, or restrict analytics to only execute on either a set of domains/hosts or ip address
LinkedIn campaign manager and Hubspot have features where you can tell the tracking script what domains to include/exclude
This is different from excluding ip addresses when setting up filters
Thanks
you can use filters on view level (Universal Analytics, not GA4) in order to exclude or include specified domains to ga data. Keep in mind, adding or removing filters work for new collected data only. Maybe add an additional view, so one view contains all data (based on your ga setup). With this solution GA collects data but will not show the data in the filtered view.
In order to fire the ga tag on a specified domain, specify the host in the trigger in Google Tag Manager, if it is implemented on page. This setting the tag will not be fired on other domains.
If there is no Tag Management on the page, you can check the domain using js before firing the ga script.
Keep in mind, that it is possible to send data to GA without fireing the GA tag by using Measurement Protocol. So if a lot of spam data appears in the interface, may add additional filters to exclude this data aswell.

Google Tag Manager - firing events from rest api

Some of my events are getting fired from frontend for both google analytics and facebook pixel and they are getting captured properly through GTM.
but now i have a functionality which is getting done from cron and is served from backend. I need to capture a event in both google analytics and facebook pixel when this is getting captured.
We need to fire the https (rest based) calls for capturing this.
Kindly help on this how this can be achieved.
Update: While this was correct at the time of writing, Google has since introduced server-side tagging via GTM, which conceivably can be used for server-to-server communication.
--
GTM has no serverside API to trigger tracking calls (the GTM API is for managing tags that will be wrapped into a Javascript function. There is no tracking backend to do calls against).
You need to send your calls directly to GA via the measurement protocol or respectively to Facebook via offline conversions.
Yes you can.
create an event listener on button click to connect to the API to collect the data
then with an event push the data you want to a Datalayer
and then use it as you wish.

Resources