Skip to main content

Sitecore Pipelines - StartAnalytics

This post documents Sitecore's StartAnalytics pipeline, and is part of a series providing information on all the pipelines and processors in involved in a Sitecore 8 request. It's not a line by line account, but all the key logic is described.

I'd like the post to develop over time, so if you find any inaccuracies, would like to contribute more information, or have useful links, then please leave a comment. Better still, contact me on Twitter.

All information has been written with reference to Sitecore 8 (rev 141212)


The StartAnalytics pipeline is started from the StartAnalytics processor in the RenderLayout pipeline, and prepares a Tracker object ready for use in the StartTracking pipeline.



CheckPreconditions

Namespace: Sitecore.Analytics.Pipelines.StartAnalytics
Assembly: Sitecore.Analytics
The CheckPreconditions processor is responsible for ensuring that all elements are in place for Sitecore to undertake tracking activities. It does this by performing the following checks:

  • The value of Tracker.Enabled must be true.
  • Context.Site must not be null.
  • Context.Page must not be null.
  • Context.Site.EnableAnalytics must not be null.

If all these criteria are met, then AnalyticsCount.CollectionTotalRequests is incremented. If not, then the pipeline aborts, and no other processors in the startAnalytics pipeline will run. 



CreateTracker

Namespace: Sitecore.Analytics.Pipelines.StartAnalytics
Assembly: Sitecore.Analytics
The CreateTracker processor simply calls the static Tracker.Initialize method. This in turn performs the following actions:

  • Tracker.Current is checked, and the method returns if it's not null.
  • The CreateTracker pipeline is run, passing in a newly instantiated CreateTrackerArgs object.
  • The method checks if the CreateTracker pipleine was aborted and returns if it was. 
  • The method switches the current tracker to the one obtained from CreateTracker (args.Tracker).



StartTracking

Namespace: Sitecore.Analytics.Pipelines.StartAnalytics
Assembly: Sitecore.Analytics
The StartTracking processor is responsible for deciding if the incoming request and the requested page are eligible for tracking. Most of the work is done by the StartTracking method on the current Tracker object. Assuming the default Tracker is being used, then the following checks are made:

  • The Tracker must not not be active (!IsActive) 
  • The Tracker must not not be sampling (!Sampling.IsSampling)
  • Analytics must be enabled (Context.Site.EnableAnalytics)

If the any of these criteria are not met, then the method returns without performing any actions.

The ExcludeRobots pipeline is run. When it completes, if the args.IsInExcludeList is true, then the following actions are performed and the processor ends without running the StartTracking pipeline:

  • AnalyticsCount.CollectionRobotRequests is incremented.
  • AnalyticsCount.CollectionRequestsIgnored is incremented.

If args.IsInExcludeList property was false, then the method checks the Ignore property of the context item's Tracking field. If it's value is true, then AnalyticsCount.CollectionRequestsIgnored is incremented and the processor ends without running the StartTracking pipeline.

If the Ignore property was false then the following actions are performed:

  • The tracker's IsActive property is set to true.
  • The StartTracking Pipeline is run.
  • AnalyticsCount.CollectionRequestsTracked is incremented.

If the StartTracking pipeline throws an exception then the tracker's IsActive propery is set to false. The Analytics.FailOnDatabaseErrors setting is checked, and if it's value is true, then the exception is re-thrown, and AnalyticsCount.CollectionRequestsTracked is incremented instead.




Comments