Google Analytics Handler for ASP
An ASP handler that reports request information to Google Analytics.
This allows you to use Google Analytics to track other requests, like media downloads (audio and video), plain text files, or XML (including RSS and Atom).
You can configure this handler in an on-premises IIS installation, or inside an Azure Web App.
Add the handler to your web application. Simply add the
bindirectory of your web app.
Add your Google Analytics Property ID as an
appSettingfor your web app. You can configure this in your
You can also set this as a connection string, which is useful in case your
appSettings are not inherited in a way that you would like, particularly if you are using the location-based redirect appSetting configuration described below.
For Azure Web Apps, you can configure this in the Azure Portal.
Configure the handler for whatever path(s) you want to report to Google Analytics. For example, to configure all
rss.xmlrequests to be recorded to Google Analytics, add this to your
You can also use wildcards here: for example, setting
path="old/*"will send all requests beneath the
old/directory to this handler.
(Optional) If you do not want to deliver a local file, but want to perform a redirect (while delivering request information to Google Analytics), then configure the redirect path as an application setting. You can configure this in your
Now any request for
/old/foo.htmlwill be redirected to
https://www.example.com/foo.htmland Google Analytics will be notified about the request for
(Optional) If you want to redirect an entire directory, such that any request within a directory is redirected to a different directory, you can configure this in your
Now any request for
/old/bar.htmlwill be redirected to
https://www.example.com/bar.htmland Google Analytics will be notified about the request for
/old/bar.html. Similarly, any request beneath the
old/directory will be handled in the same manner.