Adding Twitter Search to Google Analytics

As Twitter increasingly becomes a tool that people use to find information it is really critical for companies to know how people are finding their sites on Twitter. Doing so will allow them to incorporate that learning into future marketing efforts on Twitter as well as other sources (e.g. Google etc).

Since Google Analytics does not yet recognize Twitter search as a search engine like WebTrends or Ominiture does, I will show you how you can do it easily with one line of code.

However, keep in mind this solution only works when the search originates on Twitter (i.e. 3rd party tools like TweetDeck, those will not be captured in this solution (nor will it, I believe, be captured in WebTrends’ solution). Use this information to understand general search keywords being searched on Twitter but do not get caught up in actual number of visits that your Twitter efforts are driving.

So how do you capture searches conducted in Twitter?

GA provides a few functions to allow you to add your own search engines to the list of search engines that are already tracked by GA.

_addOrganic(newOrganicEngine, newOrganicKeyword)

You simply call this function right after var pageTracker = _gat._getTracker(“UA-XXXXXX-X”); This functions to track any custom search engine.

Twitter uses “q” as the querystring that contains the keyword. So in this case our search engine is and newOrganicKeyword is the value in query string q

So you code will look like

var pageTracker = _gat._getTracker(“UA-XXXXXX-X”);
pageTracker._addOrganic(“”, “q”)

(Note: pageTracker._addOrganic(“twitter”, “q”) will also work)

What will the reports look like in Google Analytics?

Note: For some reason I cannot get Twitter search to show up as Twitter in Google Analytics Search Engines report, it shows up as “search”(Maybe it’s a bug in GA? If anybody can provide pointer that will be a great help). However, for now this works fine as long as you know what “search” means in your search engine report. I am playing with filters and if I get that resolved I will post the fix or if you know the fix please email me.

Search Engines Report will show the following:

Drilling down to keywords will show the keywords on Twitter Search.

Looks like Twitter Search brings me repeat visits and more engaged traffic.

Originally Posted at : Adding Twitter Search to Google Analytics – Web Analytics, Behavioral Targeting and Optimization by Anil Batra in Feb. 2009

Getting Started with Web Analytics

This is a beginner guide to getting started with Web Analytics.

The easiest way to get start with web analytics and start tracking your own site or blog is to use Google Analytics.
You will need:

  • A Google Account – to sign up for Google Analytics
  • Access to your sites code to add a small JavaScript code to all the pages.

Sign into with your Google Account and follow the instructions on the screen.

Finally you will get to a page that will give a JavaScript code that you will need to copy and paste on the source code of all the pages on your site. If you site has a common header or footer file then just stick the code in that file. If you do not have a common header or footer then you will have to copy this code on every page.


After 24-48 hours you should start to see the data in your reports. You can access your reports by going to