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:
For more details and examples you can read this blog post, which is a part of blog post series on this subject.