How to link Google Analytics to your RSS feed so that you can track how many people visited the feed in ASP.NET

I spent a few days puzzling over this without luck then it hit me!

Just create a dummy page which has the Google Analytics JS embedded in it, in the OnInit of your RSS feed, use the System.Net.WebClient to load the dummy ASPX page dynamically:

protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        try
        {
            using (WebClient objWebClient = new WebClient())
            {
                objWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                Stream data = objWebClient.OpenRead(BASE_URL + "DummyPage.aspx");
            }
        }
        catch { }
    }

Comments

Popular posts from this blog

Enable Visual Studio to use more than 2GB of memory

Firefox and Chrome dark mode

Dealing with the morons who built Dell 7710 and RAID