I am trying to use BrowserHawk Reports to log statistics to my database. I have a page that performs the BrowserHawk checks, calls the LogData method, and then redirects the user. However no statistics are being logged. If I remove the redirect from the page, then the statistics are logged.
When you call the LogData method, BH sends an IMG SRC tag to the browser. When a redirect is not used in a page, the browser makes the request for the image specified by the IMG SRC tag, and this action is what results in the BRWS recording the statistics.
However when a server-side redirect is issued from a page, the browser recognizes the redirect command in the header and purposely redirects prior to loading that page's content. Therefore the browser never processes the IMG SRC tag, and as a result the BRWS never sees the statistics to be logged.
Here are some various suggestions to take to work around this browser behavior:
Consider performing your BrowserHawk checks and calling LogData from an earlier page in the user's navigation, where a redirect is not used.
Consider just performing the BrowserHawk checks and calling LogData directly from the page you are redirecting to. In other words, it should not be necessary to have a placeholder page that does nothing besides checks the browser, logs the stats, and redirects. Instead you may be able to put all of this in your destination page.
For example, if in your current approach you are redirecting to logged_in.asp, just perform your BH checks and logging directly from logged_in.asp.
You can call LogData with an optional parameter to instruct it to return the IMG SRC tag to you in a variable, rather than writing it directly to the browser. In this case you could store the return result in a session variable, and then output those results in the page redirected to. Here is some psedu-code to demonstrate:
For more details on how the BRWS works, see Understanding How Browserhawk Reports Works in the BrowserHawk documentation.
... perform BH checks
session("IMGSRCtag") = LogData(1)
... redirect to logged_in.asp
... HTML as normal
... above line must come somewhere in between BODY tags