Conversion Pipelines in Sitecore

In this blog, we will understand how we can consume the tracker’s interaction data using the Sitecore Conversion Pipelines. While consuming the data, we will try to view the list of page urls which were visited by a user in current session.

Use Case: Recently, we got a requirement in which we need to send the tracker’s interaction data to Kafka server. Then a Nifi Flow will consume the data from that Kafka topic and will process it and then sends to Sql database which BI team will use.

Before coming to execution lets understand What is tracker in Sitecore?

The Sitecore web tracker enables you to track and identify contacts and their interactions during their visit to your Content Delivery (CD) instance, in other words your website. It collects the contact (user) activities and later submits the data into xDB (XConnect) using XConnect Client API.

 Then you can use this data in personalization of content, or for creating reports or optimizing your website or any other purpose

How to enable a tracker?

Step 1: To enable the tracking, create a patch file for below config:

{siteroot}\App_Config\Sitecore\Marketing.xDB 

and set property for Xdb.Enabled and Xdb.Tracking.Enabled to true.

Step 2: Enable it at site definition like below:

 <sitecore>

    <sites>      

<site name="{site-name}" patch:before="site[@name='website']"

    ...

            enableTracking="true"/>

    </sites>

  </sitecore>

To ensure if tracker is enabled or not, you can check it at https://{sitecore-host-name}/sitecore/admin/showconfig.aspx


Once you are done with above settings, Ensure that your layout contains the MVC helper or the VisitorIdentification tag, like below: 

@using Sitecore.Mvc.Analytics.Extensions

@Html.Sitecore().VisitorIdentification()

This will allow tracker to start capturing the analytics data and at the end of the session, submitting it to a conversion pipeline that converts it and submits it to xConnect using the xConnect Client API.

Using Conversion Pipelines to capture Tracker Data

Now, lets see how we can capture the trackers data after end of session, For this we need to create a new patch like below: 

<?xml version="1.0"?>

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">

  <sitecore>

    <pipelines>

      <convertToXConnectInteraction>

        <processor patch:after="processor[@type='Sitecore.Analytics.XConnect.DataAccess.Pipelines.ConvertToXConnectInteractionPipeline.ConvertToXConnectInteractionProcessor, Sitecore.Analytics.XConnect']"

type="GlassMapperPractise.Pipelines.ConvertToXConnectInteraction, GlassMapperPractise"/>

      </convertToXConnectInteraction>

    </pipelines>

  </sitecore>

</configuration>

As you can see we are extending convertToXConnectInteraction pipeline for this task. The convertToXConnectInteraction is responsible for converting tracker interaction data into xConnect interaction data.

Then create a new class "ConvertToXConnectInteraction" which implements ConvertToXConnectInteractionProcessorBase class, like below: 

public override void Process(ConvertToXConnectInteractionPipelineArgs args)

{

    //Your logic

}

Below is how your files should look like:


Deploy your changes (Config + dll) into your sitecore root location and try to debug the code. Visit few pages of cd site and close the browser session to see the result, like below:

 



Here, i have only shown the visited url just for reference, but The Web Tracker collects page views and events as objects such as Sitecore.Analytics.Model.Entities.IContact, Sitecore.Analytics.Tracking.CurrentInteraction, and Tracker.Current.Interaction in the session.

In actual application, we have tried to log the contact details along with all the interactions , page events and goals into database.

Hope this blog give you a basic idea of using the Conversion pipelines in Sitecore.


Comments

Popular posts from this blog

Working with Device Detection Module in Sitecore

Setup A/B Testing in Sitecore - Part 1

Working with Webhooks in Sitecore - Part 1