Jonathan Svärdh
Jonathan Svärdh

Reputation: 21

Google tag manager - How can I push the Fields to set into Google Analytics?

Im trying to:

See what Search Queries in my Site search gives the visitor 0 search results.

This is what I get from the Site search tag:

Event Action 'Submit search'
Event Category 'Search'
Event Label 0
Fields to Set {page: '/sok?q=helloworld', anonymizeIp: 'true'}

What I want in Google Analytics is to see what Search query (in this case "helloworld") gave me Event label 0.

Upvotes: 0

Views: 198

Answers (1)

nyuen
nyuen

Reputation: 8907

One issue you'll have to figure out is, "How are you doing to determine that there were 0 search results returned?" since you only want to fire the event when there are no results. Are you going to scrape the page, or will you set up a listener, or will you do a dataLayer push (I recommend the last method)?

If you do a dataLayer push, then you'll have to also push an event

dataLayer.push({
   'event': 'search results',
   'numResults': 0
})

Once you have that in place, then you would need to create a URL type variable with the Query component type set with the Query key of q. Also create other associated variables, like numResults.

Then in your event tag, you can set the page field with that GTM variable, do your other settings, and then fire the tag on the search results event and when numResults = 0, all pushed from the dataLayer.

Upvotes: 1

Related Questions