예제 #1
0
        public static void TrackPageView(HttpRequestBase request, Config config, string title)
        {
            // Handle Piwik Tracking if enabled
            if (config.PiwikConfig.Enabled)
            {
                try
                {
                    // Follow Do Not Track
                    string doNotTrack = request.Headers["DNT"];
                    if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
                    {
                        string sub = request.RequestContext.RouteData.Values["sub"].ToString();
                        if (string.IsNullOrEmpty(sub))
                        {
                            sub = request.Url.AbsoluteUri.GetSubdomain();
                        }
                        if (config.DevEnvironment)
                        {
                            sub = "dev - " + sub;
                        }

                        PiwikTracker.URL = config.PiwikConfig.Url;
                        PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId);

                        // Get Request Info
                        string ipAddress = request.ClientIPFromRequest(true);
                        tracker.setIp(ipAddress);
                        tracker.setTokenAuth(config.PiwikConfig.TokenAuth);
                        tracker.setUrl(request.Url.ToString());

                        tracker.setUserAgent(request.UserAgent);

                        // Get browser info
                        tracker.setResolution(request.Browser.ScreenPixelsWidth, request.Browser.ScreenPixelsHeight);
                        tracker.setBrowserHasCookies(request.Browser.Cookies);
                        if (!string.IsNullOrEmpty(request.Headers["Accept-Language"]))
                            tracker.setBrowserLanguage(request.Headers["Accept-Language"]);
                        BrowserPlugins plugins = new BrowserPlugins();
                        plugins.java = request.Browser.JavaApplets;
                        tracker.setPlugins(plugins);

                        // Get Referral
                        if (request.UrlReferrer != null)
                            tracker.setUrlReferrer(request.UrlReferrer.ToString());

                        // Send the tracking request
                        tracker.doTrackPageView(string.Format("{0}/{1}", sub, title));
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
예제 #2
0
 /// <summary>
 /// Sets visitor browser supported plugins
 /// </summary>
 public void setPlugins(BrowserPlugins browserPlugins)
 {
     plugins =
         "&fla=" + (browserPlugins.flash ? "1" : "0") +
         "&java=" + (browserPlugins.java ? "1" : "0") +
         "&dir=" + (browserPlugins.director ? "1" : "0") +
         "&qt=" + (browserPlugins.quickTime ? "1" : "0") +
         "&realp=" + (browserPlugins.realPlayer ? "1" : "0") +
         "&pdf=" + (browserPlugins.pdf ? "1" : "0") +
         "&wma=" + (browserPlugins.windowsMedia ? "1" : "0") +
         "&gears=" + (browserPlugins.gears ? "1" : "0") +
         "&ag=" + (browserPlugins.silverlight ? "1" : "0");
 }
 /// <summary>
 /// Sets visitor browser supported plugins
 /// </summary>       
 public void setPlugins(BrowserPlugins browserPlugins)
 {
     plugins =
         "&fla=" + (browserPlugins.flash ? "1" : "0") +
         "&java=" + (browserPlugins.java ? "1" : "0") +
         "&dir=" + (browserPlugins.director ? "1" : "0") +
         "&qt=" + (browserPlugins.quickTime ? "1" : "0") +
         "&realp=" + (browserPlugins.realPlayer ? "1" : "0") +
         "&pdf=" + (browserPlugins.pdf ? "1" : "0") +
         "&wma=" + (browserPlugins.windowsMedia ? "1" : "0") +
         "&gears=" + (browserPlugins.gears ? "1" : "0") +
         "&ag=" + (browserPlugins.silverlight ? "1" : "0");
 }