1

I want to call EnsureDevice Processor from EnsureSessionContext pipeline after certain conditions met.

   public virtual void Process(PipelineArgs args)
   { 
        string countryCode= GetCountryFromIp();
        if (countryCode != "IN" && countryCode != "US")
        {
            if (HasCookieConsent())
            {
                if (HttpContext.Current.Request.Cookies["SC_ANALYTICS_GLOBAL_COOKIE"] != null)
                {
                    var myCookie = new HttpCookie("SC_ANALYTICS_GLOBAL_COOKIE");
                    myCookie.Expires = DateTime.Now.AddDays(-1d);
                    HttpContext.Current.Response.Cookies.Add(myCookie);
                }

                args.AbortPipeline();
            }
            else
            {
                Sitecore.Pipelines.CorePipeline.Run("EnsureSessionContext", new Sitecore.Pipelines.PipelineArgs());
            }
        }
    }
3
  • Please add some more detail to your question. Jan 16, 2023 at 15:26
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Jan 16, 2023 at 15:29
  • Your detail should be added to the question , not as a comment. Jan 16, 2023 at 16:03

3 Answers 3

1

You can use the same code that it's DLL (Sitecore.Analytics) is using it to call the pipeline like this.

InitializeTrackerArgs args = new InitializeTrackerArgs();
if (HttpContext.Current != null)
{
    args.HttpContext = (HttpContextBase) new HttpContextWrapper(HttpContext.Current);
    args.IsSessionEnd = HttpContext.Current.Request.FilePath == "/SESSION END";
}
EnsureSessionContextPipeline.Run(args);
if (args.Aborted || args.Session == null)
    return;
Switcher<Session, Session>.Enter(args.Session);

And here is the class that is running this pipeline.

public static class EnsureSessionContextPipeline
{
    private static AnalyticsPipelinesPerformanceContextBase _performanceContext;

    internal static AnalyticsPipelinesPerformanceContextBase PerformanceContext
    {
      get => EnsureSessionContextPipeline._performanceContext ?? (EnsureSessionContextPipeline._performanceContext = ServiceLocator.ServiceProvider.GetRequiredService<AnalyticsPipelinesPerformanceContextBase>());
      set => EnsureSessionContextPipeline._performanceContext = value;
    }

    public static void Run(InitializeTrackerArgs args) => EnsureSessionContextPipeline.PerformanceContext.EnsureSessionContextPerformanceMonitor.Monitor((Action) (() =>
    {
      if (!XdbSettings.Tracking.Enabled)
        return;
      CorePipeline.Run("ensureSessionContext", (PipelineArgs) args);
    }));
}

This way you can call the pipeline and it will execute all the processors in sequence.

0

EnsureSessionContext pipeline requires InitializeTrackerArgs object as an argument. Also, it checks for Xdb.Tracking.Enabled value. so, it should be true.

InitializeTrackerArgs initializeTrackerArgs = new InitializeTrackerArgs();
Sitecore.Pipelines.CorePipeline.Run("ensureSessionContext", initializeTrackerArgs);

Another way to call EnsureSessionContextPipeline.

InitializeTrackerArgs initializeTrackerArgs = new InitializeTrackerArgs();
EnsureSessionContextPipeline.Run(initializeTrackerArgs);

Hope it helps!

2
  • I want to call ensureDevice processor under EnsureSessionContext Pipeline, Is there any way to get there Jan 17, 2023 at 6:36
  • EnsureSessionContext pipeline has a number of processors and it is dependent on each other in terms of processing things in such order. I'd advise calling a pipeline instead of the specific processor to execute things in the right order and avoid any errors. Jan 17, 2023 at 8:03
0

There is no way of calling a single processor from a chosen pipeline. That's the whole point of pipelines - pipelines define a sequence of processors. They should be executed in a specific order as arguments which are passed through the pipeline, can be changed in processors executed at the beginning of the pipeline and further processors will use those values.

Will all the above said, you can always try to create an instance of a processor class, create object of args class and just call Process method, but that's unusual approach and I don't think you should ever do that.

E.g. when it comes to EnsureDevice processor, it must have args.Session set earlier, otherwise there will Assert.ArgumentNotNull error. And args.Session is normally set from EnsureContext processor which is called earlier in EnsureSessionContext pipeline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.