How to track searches with Google Analytics


(Camille Roux) #1

Hi,

I like to know how to track searches with Google Analytics.
Btw, are searches tracked?

Thanks


(Sam Saffron) #2

What searches are you talking about? Internal or external?


(Camille Roux) #3

Actually, I’d like the internal Discourse searches (with the icon in the top right of the page) appear in the Site Search section of Google Analytics.


(Sam Saffron) #4

hmmm … you would be dealing with some complex integration then. its probably possible to attach extra params.


(Camille Roux) #5

I don’t think so. To my mind, you just should send an event to Analytics using the same way than others pages (example: “/search?term=test”). After that, we’ll just have to define “term” as the search parameter in GA.


(Dean Taylor) #6

I would also be interested in seeing this implemented - perhaps re-categorising this thread into a “feature request”?

Google’s example to logging POST based searches is:

analytics.js: ga('send', 'pageview', '/search_results.php?q=keyword');

This method should fit well with Discourse’s search interface.

The Google Analytics documentation is here relating to search
https://support.google.com/analytics/answer/1012264?hl=en-GB

The settings in Google Analytics looks like this:

The example image also uses s for search query.

In the example image I have put in c and u as example extra parameters that might be used:

  • c = category based search
  • u = user page search
  • possible additional searches - but not sure about in-topic searches.

Not sure if this level of detail helps - but you can search many different things in Discourse - it would be nice to use Google Analytics to help visualise what users are attempting to get to from where.

Documentation mentions this:

In the Category Parameter field, enter the letters that designate an internal query category such as ‘cat, qc,’.


(Ivan) #7

So if I’m understanding this right, we just need to have a script that checks to see if we’re on the domain.com/search page, and then fire off a ga('send', 'pageview', '/search?q=keyword'); upon clicking search or hitting enter?


(Alex Armstrong) #8

Is this a thing? Is it possible to track internal Discourse searches with Google Analytics?


(James Cobalt) #9

Not quite. You could track those searches in Analytics easily enough already by URL parameter. The problem here is most of the searches probably don’t get to the search URL - the searches occur real time on the current page. Basically the script needs to post the search field text to Analytics after say, 2 seconds have passed since typing in it.


#10

Bump from the dead!

Is this right?

image

Not sure if simply putting q as a parameter is good enough, or if I need this whole /search?q= in there.


#11

I can potentially save you some work here. The new admin dashboard spec includes onsite search data. (I just need to double check with @eviltrout that we’re doing that part).


#12

could you mention me when its released?
thanks in advance


#13

I’d love to say yes but I can’t promise I’ll remember. It would be safer to follow this topic because I’ll update that when we’re done.