The data class for the Facbook Google Analytics request Took data from: - http://ga.webdigi.co.uk/ - http://www.mattromaine.com/projects/code/AnalyticsCode.html - http://www.google.com/support/forum/p/Google+Analytics/thread?tid=626b0e277aaedc3c&hl=en
Beispiel #1
0
		/// <summary>
		/// Fires the tracking event with Google Analytics
		/// </summary>
		/// <param name="request">The request.</param>
		public static void FireTrackingEvent(TrackingRequest request)
		{

			//send the request to google
			WebRequest requestForGaGif = WebRequest.Create(request.TrackingGifUri);
			WebResponse response = requestForGaGif.GetResponse();
		}
Beispiel #2
0
 /// <summary>
 /// Builds the tracking request from a Google Event.
 /// </summary>
 /// <param name="googleEvent">The google event.</param>
 /// <returns></returns>
 public TrackingRequest BuildRequest(GaDotNet.Common.Data.GoogleEvent googleEvent)
 {
     var r = new TrackingRequest();
     
     r.AnalyticsAccountCode = ConfigurationSettings.GoogleAccountCode;
     r.TrackingEvent = googleEvent;
     
     return r;
 }
        /// <summary>
        /// Builds the request from a page view request and the appSettings 'GoogleAnalyticsAccountCode'
        /// </summary>
        /// <param name="pageView">The page view.</param>
        /// <returns></returns>
        public TrackingRequest BuildRequest(GaDotNet.Common.Data.GooglePageView pageView)
        {
            var r = new TrackingRequest();

            r.PageTitle = pageView.PageTitle;
            r.PageDomain = pageView.DomainName;
            r.AnalyticsAccountCode = ConfigurationSettings.GoogleAccountCode;
            r.PageUrl = pageView.Url;

            return r;
        }
Beispiel #4
0
        /// <summary>
        /// Builds the tracking request.
        /// </summary>
        /// <param name="context">The HTTP context.</param>
        /// <param name="urlToTrack">The URL to track.</param>
        /// <returns></returns>
        public TrackingRequest BuildRequest(HttpContext context)
        {
            var r = new TrackingRequest();

            r.PageTitle = context.Request.QueryString["pagetitle"];
            r.PageDomain = context.Request.QueryString["domain"];
            r.AnalyticsAccountCode = context.Request.QueryString["ua"] ?? ConfigurationSettings.GoogleAccountCode;
            r.PageUrl = context.Request.QueryString["url"];

            return r;
        }
        /*
        /// <summary>
        /// Builds the tracking request.
        /// </summary>
        /// <param name="context">The HTTP context.</param>
        /// <returns></returns>
        public TrackingRequest BuildRequest(HttpContext context)
        {
            var r = new TrackingRequest
                        {
                            PageTitle = context.Request.QueryString["pagetitle"],
                            PageDomain = context.Request.QueryString["domain"],
                            AnalyticsAccountCode =
                                context.Request.QueryString["ua"] ?? ConfigurationSettings.GoogleAccountCode,
                            PageUrl = context.Request.QueryString["url"],
                            RequestedByIpAddress = context.Request.UserHostAddress
                        };

            return r;
        }
         */
        /// <summary>
        /// Builds the request from a page view request and the appSettings 'GoogleAnalyticsAccountCode'
        /// </summary>
        /// <param name="pageView">The page view.</param>
        /// <returns></returns>
        internal static TrackingRequest BuildRequest(GooglePageView pageView)
        {
            var r = new TrackingRequest
                        {
                            PageTitle = pageView.PageTitle,
                            PageDomain = pageView.DomainName,
                            AnalyticsAccountCode = ConfigurationSettings.GoogleAccountCode,
                            PageUrl = pageView.Url
                        };

            return r;
        }
Beispiel #6
0
		/// <summary>
		/// Fires the tracking event with Google Analytics
		/// </summary>
		/// <param name="request">The request.</param>
		public static void FireTrackingEvent (TrackingRequest request)
		{
			//Create a request for the Google Analytics GIF
            var gifRequest = WebRequest
				.Create(request.TrackingGifUri);

            gifRequest.BeginGetResponse(r =>
			{
				//ignore the response
	            try { gifRequest.EndGetResponse (r); }
                catch {
					//suppress error
				}
            }, null);
		}        
        /// <summary>
        /// Builds the tracking request from a Google Transaction.
        /// </summary>
        /// <param name="googleTransaction">The google transaction.</param>
        /// <returns></returns>
        public TrackingRequest BuildRequest(GaDotNet.Common.Data.GoogleTransaction googleTransaction)
        {
            var r = new TrackingRequest();

            r.AnalyticsAccountCode = ConfigurationSettings.GoogleAccountCode;
            r.TrackingTransaction = googleTransaction;

            return r;
        }
        /*
        /// <summary>
        /// Builds the request.
        /// </summary>
        /// <param name="pageView">The page view.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public TrackingRequest BuildRequest(GooglePageView pageView, HttpContext context)
        {
            var r = BuildRequest(pageView);

            // add users IP address
            r.RequestedByIpAddress = context.Request.UserHostAddress;

            return r;
        }
        */
        /// <summary>
        /// Builds the tracking request from a Google Event.
        /// </summary>
        /// <param name="googleEvent">The google event.</param>
        /// <returns></returns>
        internal static TrackingRequest BuildRequest(GoogleEvent googleEvent)
        {
            var r = new TrackingRequest
                        {
                            AnalyticsAccountCode = ConfigurationSettings.GoogleAccountCode,
                            TrackingEvent = googleEvent
                        };

            return r;
        }
        /*
        /// <summary>
        /// Builds the tracking request from a Google Event.
        /// </summary>
        /// <param name="googleEvent">The google event.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public TrackingRequest BuildRequest(GoogleEvent googleEvent, HttpContext context)
        {
            var r = BuildRequest(googleEvent);

            r.RequestedByIpAddress = context.Request.UserHostAddress;

            return r;
        }
         */
        /// <summary>
        /// Builds the tracking request from a Google Transaction.
        /// </summary>
        /// <param name="googleTransaction">The google transaction.</param>
        /// <returns></returns>
        internal static TrackingRequest BuildRequest(GoogleTransaction googleTransaction)
        {
            var r = new TrackingRequest
                        {
                            AnalyticsAccountCode = ConfigurationSettings.GoogleAccountCode,
                            TrackingTransaction = googleTransaction
                        };

            return r;
        }
        /*
        /// <summary>
        /// Tracks the page view  with GA and stream a GIF image
        /// </summary>
        /// <param name="context">The context.</param>
        public static void TrackPageViewWithImage(HttpContext context)
        {
            //build request
            TrackingRequest request = new RequestFactory().BuildRequest(context);

            FireTrackingEvent(request);

            ShowTrackingImage(context);

        }
        /// <summary>
        /// Tracks the page view and streams a GIF image.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="pageView">The page view.</param>
        public static void TrackPageViewWithImage(HttpContext context, GooglePageView pageView)
        {
            //build request
            TrackingRequest request = new RequestFactory().BuildRequest(pageView, context);

            FireTrackingEvent(request);

            ShowTrackingImage(context);
        }

        /// <summary>
        /// Shows the tracking image.
        /// </summary>
        /// <param name="context">The context.</param>
        private static void ShowTrackingImage(HttpContext context)
        {
            //data to show a 1x1 pixel transparent gif
            byte[] gifData = {
                      0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
                      0x01, 0x00, 0x01, 0x00, 0x80, 0xff,
                      0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
                      0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
                      0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
                      0x02, 0x44, 0x01, 0x00, 0x3b
                  };

            context.Response.ContentType = "image/gif";
            context.Response.AddHeader("Cache-Control", "private, no-cache, no-cache=Set-Cookie, proxy-revalidate");
            context.Response.AddHeader("Pragma", "no-cache");
            context.Response.AddHeader("Expires", "Wed, 17 Sep 1975 21:32:10 GMT");
            context.Response.Buffer = false;
            context.Response.OutputStream.Write(gifData, 0, gifData.Length);
            context.Response.End();
        }
         */
        /// <summary>
        /// Fires the tracking event with Google Analytics
        /// </summary>
        /// <param name="request">The request.</param>
        internal static void FireTrackingEvent(TrackingRequest request)
        {
            //send the request to google
            WebRequest requestForGaGif = WebRequest.Create(request.TrackingGifUri);
            using (requestForGaGif.GetResponse())
            {
                //ignore response
            }
        }