Filtering Google Analytics keywords with shell

What I don’t like about Google Analytics is that it lacks keyword filter. You have to use additional tools to filter phrases you need. For example, you need all keyword phrases with “finance” that drive traffic to your website. How can you find them?

You probably export a report or email it and use some “hacks” to extract data. But I can get what I need in a second. Yes, in a second. All I need is my Google Analytics Java client and unix or cygwin.

1. Get a copy of Google Analytics Java client.
2. Compile the client, run it from the command line and redirect its output to a file.

javacp [specify all params] > usorted.txt

3. Grep keywords from file.

grep ‘finance*’ usorted.txt

Done!

More tricks

1. Sort desc by number of searches

grep ‘finance*’ usorted.txt | sort -t$'\t' -nrk2

2. Save sorted output to a file

grep ‘finance*’ usorted.txt | sort -t$'\t' -nrk2 > sorted.txt

3. Save sorted asc keywords without number of searches to a file

awk '{ FS = "\t" } ; { print $1 }' usorted.txt | sort > sorted.txt

4. Run the client and save sorted output to a file (one line)

javacp [specify all params] | grep ‘finance*| sort -t$'\t' -nrk2 > sorted.txt

5. Save ‘finance*’ keywords from two, three, … websites to a file

javacp [specify all params] | grep ‘finance*| sort -t$'\t' -nrk2 > sorted.txt
javacp [specify all params] | grep ‘finance*| sort -t$'\t' -nrk2 >> sorted.txt
...
sort -t$'\t' -nrk2 sorted.txt > multiwebsites.txt
rm sorted.txt

2 thoughts on “Filtering Google Analytics keywords with shell”

Comments are closed.