2

If we wanted to provide data (get/set operations on content tree, analytics, personalization, tracking data) from Sitecore 9 to native mobile apps (not based on Sitecore Mobile SDK and Xamarin but created using IOS swift and Android java) , in this case Sitecore 9 item web service and XConnect can be utilized or XConnect with JSS can be utilized?

As per inputs from JSS slack channel Layout service can helpful but:

If user accessing the different-2 pages from mobile and in one of the page, one rendering having personalization based on Goal or User persona (Profile card) then Layout service will return personalized content for that page?

How to push tracking data for personalization ( which cookies value needs to be set from app) from native mobile app?

Please let me know, what are the ways or recommended approach to share data (content, analytics, personalization, tracking) from Sitecore 9 to native mobile apps.

2 Answers 2

2

To add more to Artsem's answer and to answer the additional questions that were not answered.

If we wanted to provide data (get/set operations on content tree, analytics, personalization, tracking data) from Sitecore 9 to native mobile apps ... , in this case Sitecore 9 item web service and XConnect can be utilized or XConnect with JSS can be utilized?

Considering the wide range of requirements, both the Item Service (Sitecore Service Client) and the Layout Service have to be used. The Item Service provides a RESTful API to create and retrieve items, though it does not support personalization and tracking. Therefore, the Layout Service has to be used to retrieve personalized content.

Using xConnect for tracking/ submitting interaction data from native mobile apps to Sitecore might not be an ideal scenario, as xConnect can receive data only from trusted clients with the correct client certificates. Therefore, if you use Sitecore 9.1 or later, it is advantageous to use Sitecore Universal Tracker. For more information and examples on how it can be done for native mobile apps, you can read this blog post. And if it is an earlier version of Sitecore, then a trusted intermediary application have to be created that receives interaction data from mobile apps and submits it to xConnect.

Considering that cookie-based tracking is not available in the context of native mobile apps, the Layout Service will not know what contact is it to be able to apply contact-related personalization. One of the approaches for how to accomplish this in the context of native mobile applications:

  • Create an API endpoint that is aware of HttpContext and Sitecore, accepts a contact identifier (e.g. username/email address) and identifies the contact.
  • A native mobile application will send a contact identifier to the endpoint by using an HTTP client and with the response SC_ANALYTICS_GLOBAL_COOKIE cookie is returned.
  • A mobile app will pass the analytics cookie with every request to the Layout Service endpoint.

not based on Sitecore Mobile SDK and Xamarin but created using IOS swift and Android java

For Android, cookie management can be handled with these HTTP clients:

And for iOS(Swift) there are also a few options, one of them involves HTTPCookieStorage, for more details you can check this answer on SO.

If user accessing the different-2 pages from mobile and in one of the page, one rendering having personalization based on Goal or User persona (Profile card) then Layout service will return personalized content for that page?

This personalization rule (based on profile card) will work only if the analytics cookie is sent from the native mobile app together with the request to the Layout Service. I've described above how it can be accomplished.

The following example is for Android, using khttp HTTP client, though you might want to implement more sophisticated cookie management mechanism.

Requesting the cookie from our identification API endpoint:

val queryStr = mapOf("identifier" to "username")
val result = get("https://yourdomain/identify", params=queryStr)

//accessing the response cookies
result.cookies["SC_ANALYTICS_GLOBAL_COOKIE"]

// "b0760a00d4cc4503a6169a1aa9cfb71a|True" -
// a device GUID/ a tracker identifier

And then sending the request to the Layout Service together with the analytics cookie:

val queryStr = mapOf("item" to "[path]",
                  "sc_lang" to "[language]",
                  "sc_apikey" to "[key]",
                  "tracking" to "[true]")

val url = "http://yourdomain/sitecore/api/layout/render/[config]"

val cookies = mapOf("SC_ANALYTICS_GLOBAL_COOKIE" to cookieValue)

//sending the analytics cookie together with request to the Layout Service
val result = get(url, cookies=cookies, params=queryStr)

The approach for personalization and tracking for the native mobile apps can be visualized with the following figure:

enter image description here

For more details and examples you can read this blog post, which is a part of blog post series on this subject.

1
  • Thanks @sergey-krivchenko, This is what exactly we have implemented except Universal Tracker. Here is one query, If Layout Service is capable enough to write interaction data from native mobile apps to Sitecore using JSS Tracker than why we need to use Sitecore Universal Tracker for the mobile apps? Commented Dec 8, 2019 at 3:18
6

In my point of view, JSS is pretty suite for your requirements. I've implemented something like you want with Xamarin. But I think it doesn't matter with which technology to do that because I didn't use any Xamarin Sitecore specific frameworks or tools. I only send simple HTTP requests to LayoutService.

If user accessing the different-2 pages from mobile and in one of the page, one rendering having personalization based on Goal or User persona (Profile card) then Layout service will return personalized content for that page?

Yes, Layout Service returns the data with applied personalization rules.

How to push tracking data for personalization ( which cookies value needs to be set from app) from native mobile app?

Actually there are a few things that you need to take into account:

  • You need to pass "tracking=true" parameter for getting personalized results ({YOUR_DOMAIN}/sitecore/api/layout/render/jss?item=/&sc_lang=en&tracking=true&sc_apikey={F3A7F3C9-0D0D-4F57-8D8A-5BFCAA4C349B})
  • You need to identify user if you want to get personalized results otherwise you will receive a content as for anonymous user

I added a web service with the following method to identify contact:

public JsonResult Identify(string email)
    {
        if (email == null) throw new ArgumentNullException(nameof(email));

        Tracker.Current.Session.IdentifyAs("identification-source-name", email);

        return Json(true, JsonRequestBehavior.AllowGet);
    }

Then I send a request to this method with contact identificator (email in my case) and it returns me SC_ANALYTICS_GLOBAL_COOKIE cookie. You need to pass this cookie with all requests to JSS. It allows you to retrieve personalized content for your contact.

The following method I've used for forgetting user in case I need to change context contact:

public JsonResult ForgetCurrentContact()
    {
        if (Tracker.Current != null)
        {
            Tracker.Current.EndVisit(true);
        }

        HttpContext.Session.Abandon();

        return Json(true, JsonRequestBehavior.AllowGet);
    }
15
  • Great answer! Just a quick note that the tracking parameter is true by default for Layout Service requests and should only need to be passed if you want to set tracking to false.
    – Adam Weber
    Commented Jul 20, 2018 at 11:40
  • I should also mention that you don't have to use the jss configuration for Layout Service. If the JSS JSON format doesn't suit your needs, you can create your own "named configuration" for Layout Service that will allow you to shape the JSON to align with your app. For instance, SXA has its own Layout Service named configuration. More info on named configurations can be found here: jss.sitecore.net/#/…
    – Adam Weber
    Commented Jul 20, 2018 at 11:42
  • @AdamWeber Thank you Adam for your notes! Actually, JSS in general and the LayoutService in particular were created as tools for achieving headless principle and it is the most matching to be used for integration between Sitecoore and any native mobile app languages. It is really flexible and probably each thing can be customized. Powerful technology! Really recommended. Commented Jul 20, 2018 at 11:54
  • I agree! I'm on the team that's building JSS :)
    – Adam Weber
    Commented Jul 20, 2018 at 12:22
  • I know :) I was in the round table session with you at SUGCON :) Commented Jul 20, 2018 at 12:24

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.