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

IIS_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:

IETypes

 

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 (6)

  1. Steve says:

    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.

  2. Thanks for the post.

    Another option is to group by ‘Browser’ and to output to text file.

  3. d34thw4g0n says:

    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 Hits

  4. Natalia says:

    Thank for this example, realy useful to find solution to case sintaxs error!

  5. elorg says:

    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

Skip to main content