Custom Filters for GA, Part 4b: Custom Advanced


Custom advanced filters can be very cool. You can use them to rewrite stuff. And much cooler, you can use them to associate stuff.

For example, you can use an advanced filter to associate a Request URI (a page someone asked for) with a Campaign Medium (the medium they used to get to your site) and then dump it all back into Request URI (so that you can see it in your Content > Top Content report.) Before I go into the technical details, you may be saying, why would I ever want to do that? Well, if you have 10,000 URIs and you want to look at them all in Excel, it would be nice to have a report that you can download into a csv file and then sort any way you like.

So here is a screenshot of what that filter would look like. (Ooh, many thanks to Steve and to our web designer, both of whom gave me the same advice on better screen shots. So now this one is legible:)


Notice the A and B stuff in the middle. Here is what I am telling Google:

My field A is Request URI. Get everything, by using .* and put it in a variable, by using parens, so get-everything-and-put-it-in-a-variable looks like (.*)

My field B is Campaign Medium. Once again, get everything and put it in a variable, hence (.*)

Now comes the magic. Output it all to Request URI. And format it so that I see the A variable (that’s why I used $A1) and then a colon, and then the B variable. That last field, constructor, is not a regular expression. You can write anything you want there — I could have written $A1/$B1, or I could have written, $A1 AND $B1, etc. Also note: in the A field, there is only one variable, (.*), so I used $A1. Same for B. But there might be two variables, and then I would use $A1, or $A2, etc.

Choosing where to output your new mashed up string is important. For example, if you want to see, how many people came through a banner ad medium, touched the home page, and then converted, you wouldn’t want to use the filter I just created — even though it creates the correct information, a mashup of the medium they came in on with the page they touched. That’s became this particular example gets output to content >top content, a report that doesn’t include conversion. A better place to output it to would be campaign name. That way, it will get dumped into your campaign report, which has conversion associated with it.

If you are doing this kind of mashup, it is vital to create a new profile first. After all, you probably need most of the reports “unmashed” for some things, and if you do this in a separate profile, you can mess around all you want, while leaving your production data untouched. Need to learn more about creating new profiles?

Endnotes: Many thanks to Caleb Whitmore from POP, who taught me so much about custom advanced filters when we were at Google training. Caleb actually wrote this particular filter a few months ago. And to Dylan Lewis, for getting our new address right, and for letting his web analyst, Joy Billings, be co-chair of the WAA marketing committee. I have really awesome pictures of both Caleb and Dylan.

Our founder, Robbin Steif, started LunaMetrics in 2004. She is a graduate of Harvard College and the Harvard Business School, and has served on the Board of Directors for the Digital Analytics Association. Robbin is a winner of a BusinessWomen First award, as well as a Diamond Award for business leadership. In 2017, Robbin sold her company to HS2 Solutions and has since retired from LunaMetrics.

  • steve

    RE: Screenshots and Galleries.
    Robbin you asked a while ago about galleries and such, in addition to the screenshot above? I just came across a huge list of WordPress plugins for dealing with photo’s etc:

    Having a very quick scan and the like, these two seem halfway decent and simple. YMMV…

    Both seem to have all the things I’d look for: Been around for a few years. Current support from the author. Semi-active development.

  • Pingback: Judah Phillips at Web Analytics Demystified » Blog Archive » Part II: Google Analytics V2 is AWESOME, but still falls short for my complex needs…()

  • Laura

    Ach! I am trying to understand filters. Your posts on regex gave me everything I needed to know (have you thought about talking to Google to see if they want to hire you to write their help pages??? – you can use me as a reference – heh heh). I am successfully using regex now (a pat on the back for yourself is well deserved at this point).

    However, as for filters…I have an aggregate profile and then duplicate profiles for several sites (all use ua-xxxxx-1). Now, being the logical person that I am, I noticed that the profiles all showed data without any help from me (well other than putting code on pages). So, since the aggregate profile shows traffic to all sites, I *assumed* (the first red flag, right?) all I would have to do is write an ‘exclude’ filter, leaving only one domain name per profile.

    HA! It didn’t work. Help pages were…well, not helpful. I found a blog somewhere in the middle of the wee hours of the night that told me to write – of all things – an ‘include’ filter. WHAT? That seems backwards to my Spockish brain. *Sigh*, of course, it worked, but I want to know why. Any pearls of wisdom or sites you can suggest so I can learn filters….


    humbled daily by the ‘illogical’ world of Analytics…..

  • Hi Laura. Thank you for the compliment. I think that Alden at Google Analytics would be horrified if I took his job. But thanks anyway.

    As for include/exclude. The truth is, you could do it your way too, But, let’s make the problem a little easier, and let’s assume that you are tracking a site with many different directories. All the profiles have the same UA code, and you want one profile that shows and one that shows and one that shows and one that shows

    So the first one, we will say, needs to *include* blog and exclude conversionrate, emarketing and aboutus. You can write a custom exclude filter to exclude Request URI that matches ^/conversionrate and one that matches ^/emarketing and one that matches ^/aboutus. (You can even put them all together with OR pipes, I am just too lazy to go test it.) Alternatively, you can simply write an include filter that matches request URI ^/blog, which is a whole lot easier.

    I realize that I have dumbed this down a little bit, but once you add in different domains, I would feel guilty not dealing with the cross-domain issues here. This handles the include/exclude without the extra layer of complexity (I hope.)

    I have more stuff on filters coming soon, but first I have to add one more RegEx post.


  • Paul

    Hi Robbin,

    I’m trying to set up a Custom Filter that will allow me to get a little more information from some urchinTracker fake URIs tracking javascript events. Right now I have the request URI attached to campaign source and being outputted into campaign name, but when I look at the reports the campaigns are listed with all zeros in the data.

    Am I doing something wrong here? Is there another way I should be doing this? I tried just now switching it to campaign medium so my filter is set up the same way as yours and am waiting for GA to update.

    Thanks, great posts on the subject.


  • Hi Paul, can you write out how you did it and what they do and mostly, what you want to achieve? It would seem to me that it you have a javascript event like onclick and an urchinTracker(‘/outbound/otherjunkhere/’), you would have a very hard time using campaign medium OR campaign name to filter those “pages” the way you are trying, because all those variables (campaign, source, medium) are session level variables, and you are tracking a page, not a session. And they don’t mix super well, although they do mix sometimes.

    I keep wanting to do a post on this topic, but I have to locate an old post that Justin Cutroni wrote on this topic, and I can’t find it.

  • Paul

    Hi Robbin,

    We have a few urchinTrackers to measure chat events from a third party proactive chat client we’re testing out, all starting with /chat/. I’ve set up a conversion goal for each of these as well, so we at least have something to measure the success of these events by.

    What I did was was take everything from Campaign Medium in Field A and then take Request URIs that match (/chat/.*) for Field B and output them to Campaign Name as $A1,$B1. The information was placed in as different campaign names, however each field of information was zero.

    Ideally I would of course love to get all of the session data that Google collects and separate them into sessions where someone accepted a chat, sessions where there weren’t any chat people available, etc. Anything to get a little more insight into the behavior of customers who encounter the new chat feature.


  • Paul – is your ultimate goal to understand WHERE THOSE CHATS ORIGINATE? Or, is your ultimate goal to understand WHAT HAPPENS TO THE INDIVIDUAL WHO TRIES TO CHAT?

    If the latter (which is where I think you are going) — describe how the event changes when there isn’t a chat person available. For example, does the request URI change? Or do they just get a “no one home” message?

    From the little I understand here about your company needs, you have to match them with the right fields. I don’t think anything that starts with the word “campaign” is going to get you where you need to be.

  • Paul


    That’s right, we’re looking for the latter.

    I’m tracking four events, chat accepted, chat declined, chat rule triggered, and no chat reps available. It’s all proactive chat, so the visitor does very little. We have a set of rules modelling different actions on the website (views a page for 60 sec, searches for something that doesn’t exist, etc.) and when a customer completes one of these rules we first check the availability of our agents and then pop up a div layer inviting them to chat if there is an agent available. The request URI doesn’t change, when a customer accepts a chat we pop up a window with the third party chat client. When a rule is triggered or an agent is not available nothing happens on the customer side of things, we just call some javascripts which include the urchintracker within them to record them.

    I hope that’s not too much detail, and if you can point me in a direction of which variable would help me out I’d be quite grateful.


  • Oh, I get it now. But you are still faced with, what do you want to measure?

    So let’s say that you have urchinTracker(‘/chat/success/’) and urchinTracker(‘chat/NoRep/’)

    Now what? Do you want to figure out if the person who had success is more likely to make a purchase and arrive at the /thankyou/ page? In which case, you need to set up a goal that has the page /chat/success as the first (and required) step and /thankyou/ as the goal. Not a filter.

    Maybe, however, you want to throw all the GA tools at your different chats. In which case, you want a separate profile for each one, with a separate include filter. So you only need to create a custom filter where the request URI matches /chat/success/ and another profile where the custom filter has a request URI include that matches /chat/NoRep/

    No matter how I look at it, you wouldn’t ever be using campaign and source. That stuff is all about , how did the visitor find me, not what did they do once they initiated a chat.

  • Paul

    Ah, that’ll do it. I was skeptical that just conversion data would give me enough information, but I think those extra profiles will do the trick.

    Basically I was looking for a workaround the lack of multi-segmentation with the utmsetvar function by throwing the request URI at any of the campaign or visitor info and seeing if it would stick. More wishful thinking than anything else.

    Thanks for the help with this, and thanks for all of the info on the blog.

  • I would say very informative article, go to know about filters and their specific working. I want to thank the writers and Paul and Robbin for their comments.

  • Perfect, exactly what I was looking for.

    I have several subdomains (www, forum and blog) but I like having unified reporting across them. Now I can rewrite the RequestURI to indicate the different domains.

    Thanks, Oliver

  • Pingback: » Blog Archive » Scripted Multiple Resizes With ImageMagick()

  • Pingback: Filters for Google Analytics: Cascading Custom Advanced Filters()

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187