Sending background hits

 

Utility of identification

Identification enables you to distinguish hits sent following direct usage of your application from hits sent in the background, automatically and independently of the user, with the help of a BackgroundWorker for example.

 

Tagging

The tracker possesses a Context object, which possesses a property, BackgroundMode. This is BackgroundMode-type enumeration.

By default, this property is set to Normal. In all cases of tagging automatic behaviours independent of the user, it should be set to Task.

To tag these types of operations, you must initialise a new tracker within your class in the case of a Service.

In the case of a BackgroundWorker, it is recommended to use a dedicated instance of the tracker. Should you wish to use a single instance of the tracker, please remember to reset the property to Normal at the end of the BackgroundWorker execution.

 

Tagging examples

  1. Tagging an BackgroundWorker with a dedicated tracker
    private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
         Tracker bgTracker = SmartTag.Instance.tracker("backgroundTracker");
         bgTracker.Context.BackgroundMode = BackgroundMode.Task;
         bgTracker.Gestures.Add("async_download").SendDownload();
         // ...
    }
    
    public void BackgroundTask ()
    {
         BackgroundWorker bw = new BackgroundWorker();
         bw.DoWork += new DoWorkEventHandler(bw_DoWork);
         bw.RunWorkerAsync();
    }
    
  2. Tagging an BackgroundWorker with a global tracker
    private void bw_DoWork(object sender, DoWorkEventArgs e)
    {
         tracker = SmartTag.Instance.defaultTracker;
         tracker.Context.BackgroundMode = BackgroundMode.Task;
         tracker.Gestures.Add("async_download").SendDownload();
         // ...
    }
    
    private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
         bgTracker.Context.BackgroundMode = BackgroundMode.Normal;
    }
    
    public void backgroundTask ()
    {
         BackgroundWorker bw = new BackgroundWorker();
         bw.DoWork += new DoWorkEventHandler(bw_DoWork);
         bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
         bw.RunWorkerAsync();
    }
    
 

Was this post helpful?

Last update: 29/10/2015