Keith Savoie
Keith Savoie

Reputation: 3

Google Analytics - How to filter by page, group by query string value?

I have a site with a store search that posts in the following format. www.site.com/store-locator?city=&province=&zip[postal_code]=68123

I am trying to configure GA to give me feedback on people visiting this page and a count of specific zips searched.

example report data

  1. /store-locator?city=&province=&zip[postal_code]=68123 1000 visits
  2. /store-locator?city=&province=&zip[postal_code]=68456 768 visits
  3. /store-locator?city=&province=&zip[postal_code]=68789 221 visits

note: the 'city' and 'province' values may also be populated (and I will want to mod GA to give similar data on these too).

Can anyone give feedback on how to configure GA to give me data similar to this?

Thanks!

Upvotes: 0

Views: 3298

Answers (2)

vaquar khan
vaquar khan

Reputation: 11449

/store-locator?city=&province=&zip[postal_code]=68123 1000 visits

Step 1: In GTM, create a new macro. I called mine {{province}}

Macto Type = URL
Component Type = Query
Query Key = province

This will populate the Macro with the value of province from the query string.

Step 2: In your Google Analytics property, define a custom dimension called "province". This will assign an index key to the dimension.

Step 3: In your GTM tag for Google Analytics, you will find Custom Dimensions under more settings. Add a new dimension, apply the index number from #2 and for the dimension select the macro you created from #1

Publish and you are all set.

Now when you look in Google Analytics, you can add a secondary dimension and choose your newly created custom dimension.

Upvotes: 0

here
here

Reputation: 2859

As far as I know, the only way to look at this type of segment historically is using individual segments, which doesn't work well for an arbitrary number of zip codes. However, you can collect this data more effectively as described for new traffic. This comes up often with information like categories, tags, dates, query string variables, etc.

To use Custom Dimensions, you would pass the zip code to google analytics explicitly when calling the analytics javascript code.

You can pull querystrings with javascript, or echo the parameter using something like PHP as follows:

<?php
    if (array_key_exists("zip",$_GET)) { $theZip = $_GET["zip"]; }
    else { $theZip = "nozip"; }
?>

And, sending the custom dimension --

ga('create', 'UA-XXXXX');
ga('set', {'dimension1': '<?php echo $theZip; ?>'})
ga('send', 'pageview');

You also need to setup the custom dimension in the Analytics Profile. Docs on custom dimensions https://developers.google.com/analytics/devguides/platform/customdimsmets

Upvotes: 1

Related Questions