You can do this setup via GTM or directly in code. Ideally, you should get everything set up with GTM and then configure the custom event in GA4 by following these steps: In Google Tag Manager (GTM) , follow these steps: Log in to GTM and go to your container. Click on “Tags” in the left navigation panel and then “New” to create a new tag. Select “Google Analytics: GA4 Event” as the tag type.
Enter your GA4 Measurement ID or select malta number data the corresponding variable. , such as “search” or “internal_search”. In the “Event Parameters” section, add a new parameter called “search_term” and bind it to the variable that contains the search term (for example, the “URL Query” variable with the search parameter identified in step 1). Set up an appropriate trigger for the tag, such as “History Change” or “Page View” with conditions that match your website’s search URL.