Logparser: Calculate No. of hits for different Browser type from IIS Logs
Why you need to know this:
To figure out what kind of browser(IE, Firefox, Safari) requests are coming for your application.So that you can make sure your application is compatible with that browser type.
IIS 6 Log
You can put the following into *.bat file and double click to execute.
Srcnt ==> It Returns the number of occurrences of a substring in a string , if not found then 0 is returned
@echo OFF
"C:\Program Files\Log Parser 2.2\logparser.exe" "select case strcnt(cs(user-agent),'Firefox') when 1 THEN 'Firefox' else case strcnt(cs(user-agent),'MSIE+6') when 1 THEN 'IE 6' else case strcnt(cs(user-agent),'MSIE+7') when 1 THEN 'IE 7' else case strcnt(cs(user-agent),'Safari') when 1 THEN 'Safari' else case strcnt(cs(user-agent),'Opera') when 1 THEN 'Opera' ELSE 'Unknown' End End End End End as Browser,count(cs(User-Agent)) as Hits into c:\pie.gif from C:\LogParserBlog\ex.log group by cs(User-Agent)" -chartType:BarStacked -o:chart -values:ON -view:ON
EXIT
Output:
You can modify above query to include more browser type for example Opera
Else case strcnt(cs(user-agent),'Opera') when 1 THEN 'Opera' END
Hope this helps :)
Comments
Anonymous
November 12, 2008
PingBack from http://www.tmao.info/logparser-calculate-no-of-hits-for-different-browser-type-from-iis-logs/Anonymous
February 23, 2009
I believe that there's a bug in your script. The user agent string for Chrome contains the word Safari. So all Chrome browsers will be recorded as Safari instead.Anonymous
March 03, 2009
Thanks for the post. Another option is to group by 'Browser' and to output to text file.Anonymous
August 28, 2009
regarding the user comment by Steve... I had the same issue with Chrome, AOL and mobile devices as they typically fell into another larger category like Safari, or MSIE in the case of AOL. What I ended up doing as a work around was to just count the items that would be included in two search strings first. example... count Chrome before Safari this is what i am using (work in progress) select case strcnt(cs(user-agent),'Firefox') when 1 THEN 'Firefox' else case strcnt(cs(user-agent),'AOL') when 1 THEN 'AOL' else case strcnt(cs(user-agent),'Opera') when 1 THEN 'Opera' else case strcnt(cs(user-agent),'Chrome') when 1 THEN 'Chrome' else case strcnt(cs(user-agent),'Mobile') when 1 THEN 'SmartPhone' else case strcnt(cs(user-agent),'Safari') when 1 THEN 'Safari' else case strcnt(cs(user-agent),'MSIE+6') when 1 THEN 'IE 6' else case strcnt(cs(user-agent),'MSIE+7') when 1 THEN 'IE 7' else case strcnt(cs(user-agent),'MSIE+8') when 1 THEN 'IE 8' ELSE 'Unknown' End End End End End End End End End as Browser,count(cs(User-Agent)) as HitsAnonymous
June 06, 2012
Thank for this example, realy useful to find solution to case sintaxs error!Anonymous
June 17, 2014
Awesome! I tweaked the query a bit and used it in Log Parser Studio: select case strcnt(cs(user-agent),'Firefox') when 1 THEN 'Firefox' else case strcnt(cs(user-agent),'AOL') when 1 THEN 'AOL' else case strcnt(cs(user-agent),'Opera') when 1 THEN 'Opera' else case strcnt(cs(user-agent),'Chrome') when 1 THEN 'Chrome' else case strcnt(cs(user-agent),'Mobile') when 1 THEN 'SmartPhone' else case strcnt(cs(user-agent),'Safari') when 1 THEN 'Safari' else case strcnt(cs(user-agent),'MSIE+6') when 1 THEN 'IE 6' else case strcnt(cs(user-agent),'MSIE+7') when 1 THEN 'IE 7' else case strcnt(cs(user-agent),'MSIE+8') when 1 THEN 'IE 8' ELSE 'Unknown' End End End End End End End End End as Browser,count(cs(User-Agent)) as Hits from '[LOGFILEPATH]' group by Browser