Parsing Querystring Values in Fiddler Custom Rules

 

I’ve been hot-rodding Fiddler for some time now to make my life a lot easier when debugging my site tagging and analytics tracking requests.  You can customize just about anything within the sessions window from the color, background, custom columns to the request it actually makes.  I’d previously created a custom column called “EventType”, which was reading in a value sent back in the response body as part of our own tracker when in a “debug” mode.  We’re now switching over to use Snowplow as our tracker technology, so I wanted to add in the event type for Snowplow events.  Snowplow describes all the special sauce to decoding their tracker request URLs, which is what I used to parse out what the event being sent is.  You could do a similar breakdown for Google Analytics, Site Catalyst etc…

Parsing the Querystring

Fiddler script is some weird amalgamation of .NET code and Javascript, with a syntax like Classic ASP.   You can easily access anything within .NET, it will just look nothing like you’d expect…  I’d like to easily pull out querystring parameter values by name to determine the Event Type to show in the column.  We can use the .NET HttpUtility.ParseQueryString, all we need to do is add the proper Imports:

 

import System;
import System.Windows.Forms;
import Fiddler;
// add in system web
import System.Web;

Then we can use the method to parse the querystring. The Fiddler session object doesn’t provide us quick access to just the querystring, so we do have to parse it out of the URL.

//I like to pad the end with a "?" so split will always have a [1] index
// in the event there is no querystring present
var s_qs = (oSession.url + "?").split("?")[1];

var querystring = HttpUtility.ParseQueryString(s_qs);
// now we can easily .Get any querystring value by name
var s_event = querystring.Get("e");

Snowplow Events

For Snowplow events, I decided to set up event types for the following:

  • Page View
  • Page Ping
  • Structured Events
    • Return the event “Action”
  • Unstructured Events
    • Return the event “name”

 

public static BindUIColumn("EventType", 60)
function FillEventTypeColumn(oSession: Session){
	//check for whatever the tracker request domain is
	if(oSession.HostnameIs("collector.garrettpatterson.com")){
		//I like to pad the end with a "?" so split will always have a [1] index
		// in the event there is no querystring present
		var s_qs = (oSession.url + "?").split("?")[1];

		var querystring = HttpUtility.ParseQueryString(s_qs);
		var s_event = querystring.Get("e");
		var s_eventtype = "";

		switch(s_event){
			case "pv":
				s_eventtype = "PageView";
				break;
			case "pp":
				s_eventtype= "PagePing";
				break;
			case "se":
				var s_action = querystring.Get("se_ac");
				s_eventtype =  s_action;
				break;
			case "ue":
				var s_name = querystring.Get("ue_na");
				s_eventtype = s_name;
				break;

		}

		return s_eventtype;
	}
}

The screenshot shows the snippet of the Web Sessions window with the Snowplow EventTypes populated among the other tracking requests:

Happy Hacking!

1 thought on “Parsing Querystring Values in Fiddler Custom Rules

Leave a Reply

Your email address will not be published. Required fields are marked *