Configure Google Analytics

If you are using the Doofinder layer in your website, you can get a lot of information about the search from Google Analytics. Let's see how.

🗒️ Note:Classic google analytics (ga.js) is no longer supported. Upgrade to universal analytics (analytics.js) to have doofinder & google analytics integration.

Analytics In Doofinder Layers

If you use Google Analytics in your site, Doofinder will automatically try to send two types of events to your account:

  • Search Events: These kind of events are triggered when users stop typing on the search box of your site. After a small, configurable pause, the event is sent to Google Analytics. Also, you can configure your layer to send searches as page views too if you want to have that kind of information.
  • Click Events: These events are asynchronously sent when a user clicks on a search result. They are only sent once per search so, if the user clicks the result by pressing the CTRL/COMMAND key of the keyboard to open the result in a new browser tab, and then clicks it again without performing a new search, the event is sent only once.

If you want to know internals about how the layer works, continue reading. Otherwise you can skip to the next section.

How It Works

📌 Note: If you want to debug Google Analytics integration in Doofinder layers, we recommend using the Google Analytics Debugger Chrome extension.


🗒️ Note:This article is not a reference. To learn how to configure Google Analytics options for the layer check the documentation for the right version of your layer.

OK, you feel intrepid, and you want to learn more about how this stuff works. Let's go then.

CHOOSING A TRACKER

When the layer loads it looks for Universal Analytics stuff in your page (window.ga, …) and, if everything is OK, the layer can start sending events to Google Analytics.

By default, Doofinder layer tries to use the default Google Analytics tracker but, if you have multiple trackers or you use custom tracker names, it may happen that the layer doesn't know where to send events. If that's the case the layer may be sending events to the wrong tracker or may not be sending events at all.

DEBUGGING TRACKER SELECTION

The no-code way to know if the layer is trying to send events to Google Analytics is to use the Google Analytics Debugger plugin in Chrome so, once installed, visit the page where you have your Doofinder layer and open the developer tools (CTRL+MAYUS+I on Windows, CMD+ALT+I on Mac). Then go to the Console tab and reload the page. If you are using Google Analytics you will see something like this:

Ok. Let's see how to identify our tracker.

If you use the regular Google Analytics script you should see something like this:

Running command: ga("create", "UA-XXXXXXXXX-Y", {cookieDomain: "auto"})

And, performing a search in the layer, you should see:

Running command: ga("send", "event", {eventCategory: "doofinder", eventAction: "search/6a96504d…", eventLabel: "search something"}) |- Sent beacon: …

If you saw that, means that events are being sent. If you see this instead:

Running command: ga("send", "event", {eventCategory: "doofinder", eventAction: "search/6a96504d…", eventLabel: "search something"}) |- Command ignored. Unknown target: undefined

You're probably using Google Tag Manager or a custom tracker, and the layer is not targeting the proper tracker.

To confirm this, locate the tracker creation commands. They probably look like any of these:

Running command: ga("create", "UA-XXXXXXXXX-Y", {name: "gtag_UA_XXXXXXXXX_Y"}) // GTM

Running command: ga("create", "UA-XXXXXXXXX-Y", {name: "myTracker"}) // Custom Tracker

Well, at least you have a tracker name to use.

SPECIFYING A TRACKER

If the layer is sending events to the wrong tracker, you may explicitly provide the name of an existing tracker:

{ googleAnalytics: 'gtag_UA_XXXXXXXXX_Y' }

{ googleAnalytics: 'myTracker' }

Or, if you don't know what tracker name provide, or you're not receiving any events from the layer, you may provide a Google Analytics account ID in the googleAnalytics layer option and a custom tracker will be created.

Passing an account id to the layer:

{ googleAnalytics: 'UA-XXXXXXX-Y' }

Sending Events

Once the layer has a tracker it can use, it will be able to send events:

  • Search Events: When a search event is sent, the action of the event looks like search/, being hashid the internal ID of your search engine in Doofinder. The event label will be the search terms typed by the user.
  • Click Events: When a click event is sent, the action of the event looks like click/, being hashid the internal ID of your search engine in Doofinder. The event label will be the URL of the search result being clicked.

All events sent by Doofinder belong to the doofinder event category.

In the previous section we mentioned that searches could be tracked as page views. This feature is disabled by default and must be enabled explicitly in the layer options. Once enabled, searches will be additionally logged by sending page view events through the current tracker.

The URL of the page view would look like:

/doofinder/search/<hashid>?query=<query>

being hashid the internal ID of your search engine in Doofinder, and query the search terms typed by the user.

And that's all. Simple enough, right?

Google Analytics has a special section for Site Search inside the Content section. Here you can see reports of the search terms, visits with search, etc. To make these reports work you have to follow these simple steps:

  1. Go to the Admin panel of Google Analytics.
  2. Select the Account, Property and View for which you want to set up Site Search.
  3. Click on «View Settings» and you'll see something like this:
  4. Switch On «Site Search Tracking» at the end of this page.
  5. Type «query» into the «Query parameter» input and save changes. You're done.

If you have a previously configured query parameter you can add this one separated by a comma, like «myparameter, query».

Doofinder as a Campaign

If you want to track more information about the use of Doofinder, and how many conversions you get from users using Doofinder you can set up a Google Analytics campaign.

To do this you simply have to add the appropriate Google Analytics parameters to the links of your products in the feed file.

Here you can see how Google Analytics campaigns works, but let's see an example:

Suppose one of the links of your products is like this:

http://mysite.com/product.php?id=2311

You have to change the links in your feed to make them look like this one:

http://mysite.com/product.php?id=2311&utm_source=Doofinder&utm_medium=Doofinder&utm_campaign=Doofinder

Of course you can choose any other names you like for the campaign.