How to Resolve an Interaction Channel Using a Query String in Sitecore

What does “Channel” term mean in the Sitecore context? Channel is the source or the paths that contacts use to interact with your brand through campaigns and face-to-face interactions. Sitecore defines why you need them:

“When you view how contacts interact with your website, it can be helpful to track the channels that your contacts use to come to your website. This can give you more insight into how contacts interact with your brand, which channels bring the most traffic to your campaigns, and which channels lead to the best goal conversion rates.” (https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/marketing_operations/channels/the_online_channels_and_their_subchannels)

Let’s imagine that we have some specific ways how users interact with our application. It can be some web api, services and etc. In our case, we use JSS Layout service to provide data for Xamarin app and we want to associate interactions of the mobile app with, for example, “App usage” channel.

Our requirement can be easily resolved by passing an id of the “App usage” channel in a query string parameter in a layout service url.

First of all we need to `QueryStringChannelResolver` processor:

   using Sitecore.Analytics.OmniChannel.Pipelines.DetermineInteractionChannel;
using Sitecore.Data;
using Sitecore.Diagnostics;

namespace Jss.Demo.App.Pipelines.Channel
{
    public class QueryStringChannelResolver : DetermineChannelProcessorBase
    {
        public override void Process(DetermineChannelProcessorArgs args)
        {
            Assert.ArgumentNotNull((object)args, nameof(args));
            if (string.IsNullOrWhiteSpace(Sitecore.Context.Request.QueryString["channelId"]))
                return;

            var queryString = Sitecore.Context.Request.QueryString["channelId"];
            ID channelId;
            if (ID.TryParse(queryString, out channelId))
            {
                args.ChannelId = channelId;
            }
        }
    }
}

And then to register it in “determineInteractionChannel” pipline:

   <!--?xml version="1.0" encoding="utf-8" ?-->
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<determineInteractionChannel>
<processor
type="Jss.Demo.App.Pipelines.Channel.QueryStringChannelResolver, Jss.Demo.App"
patch:after="processor[@type='Sitecore.Analytics.OmniChannel.Pipelines.DetermineInteractionChannel.DefaultChannel, Sitecore.Analytics.OmniChannel']">
</processor>
</determineInteractionChannel>
</pipelines>
</sitecore>
</configuration>

After that, our request url became to look like the following:

   http://{our-url}/sitecore/api/layout/render/jss?item={PATH}&sc_lang=en&sc_apikey={apikey}&channelId={1914DA0E-9C3A-4EC3-A2C2-A12EED2A4577}&tracking=true

Now we can track the interactions from our mobile app separately from the site activities:

interaction channels sitecore