Reputation: 2786
In Google Analytics v3 it was possible to send custom events right from the frontend of the application, like:
gtag('event', 'my_custom_search', {
'event_category': 'custom_text',
'event_label': 'custom_label',
'value': 'custom_value',
});
In GA4 it's still possible to send predefined events, like search
for example:
gtag('event', 'search', {
search_term: '1234'
});
Now we want to send our custom events again. So I simply tried this:
gtag('event', 'my_custom_search', {
search_term: '1234'
});
Unfortunately the custom event doesn't show up in the realtime view. I found this article to create custom events in the backend: [GA4] Modify and create events via the user interface.
My questions are:
If the anser to the second question is yes, then this is a lot of extra work, because we have to define the events in the Google Tag Manager and also in our frontend.
Upvotes: 2
Views: 1374
Reputation: 479
The my_custom_search
should be able to fire, however, you'll need to install gtag
before running your custom code, which is to set up the measurement id with gtag
. You can reference google's document at here.
Upvotes: 0
Reputation: 5198
Current state, you'll have to name/configure them in GA4. Be careful of the limits, as you can't delete them. So no, you can't name them on the fly.
For your example, you'll want to keep it to the default "view_search_results" event, but augment via additional parameters, "type=custom"
As for your GTM question. This depends on how complex your GTM setup is currently and how well your events fit into the GA4 default list of events. Again you'll want to review and fit your existing events into the default events where possible and add new ones only after you've done the full review.
Implementation-wise, you might be able to reduce the number of tags by using a lookup table for existing events to map them to GA4 event parameters.
Edit: also you're referencing "gtag" a lot, it is different from Google Tag Manager. If your current custom events implementation is done through gtag then the migration will be more manual.
Upvotes: 2