Skip to content

PageView

Linda Lawton edited this page Jul 1, 2018 · 1 revision

Pageviews are sent when a user views a page on your website. This is a simple class that will create a hit and send it.

  • pageview hits can only be sent to web google analytics accounts.
  • Document location must be sent.
  • Response is always a gif. Google analytics does not notify you of failure. see note below
class PageViewHItSender
    {
        public static bool Send(ITracker tracker)
        {
            var hit = new PageViewHit("https://github.com/LindaLawton/google-analytics-dotnet-sdk")
            {
                UserId = "123456",              
            };

            var request = (Hitrequest)tracker.CreateHitRequest(hit);           
            var collectRequest = Task.Run(() => request.ExecuteCollectAsync());
            collectRequest.Wait();
            Console.Write(collectRequest.Result.RawResponse);
            return true;
        }

    }

Note: Google analytics doesn't actually verify that the it was sent. You will receive a gif back with every hit even if it fails. You should do a debug test on your hits in testing before going to production and sending the actual hits.

Tracker Quick Start

Hits Quick Start

Change log

Change log

Clone this wiki locally