Sitecore Personalization JSS Tracker vs Layout Service.

Abhishek Malaviya
2 min readJun 3, 2019

--

JSS Tracking

JSS ships with an analytics tracking API that allows pushing Sitecore analytics events to the xDB based on client-side behavior in JSS apps. In a client-side app, we do not have access to the server-side APIs normally used to report analytics events to XConnect. Instead, the JSS Tracker API allows us to push analytics events, such as page/route views, events, goals, and outcomes, directly from the client.

The JSS tracker comes installed but disabled by default when the JSS server components are installed. To enable the JSS tracker, patch the Sitecore.JSS.TrackerServiceEnabled setting to true in a configuration patch file such as:

<configuration>
<sitecore>
<settings>
<setting name="Sitecore.JSS.TrackerServiceEnabled" value="true" />
</settings>
</sitecore>
</configuration>

Layout Service

Layout Service requests are tracked on the server-side as a ‘page view’ just like a traditional Sitecore site would. This includes any goals, events, etc configured to be triggered by the route item. Requests to Layout Service will track a page view by default. This can be disabled by adding tracking=false to the Layout Service request query string (configurable via the dataApi object in JSS apps). Disabling LS tracking may make sense if all page tracking is to be handled using the tracking API.

As mentioned above Layout Service by default can collect analytic data. But JSS Tracking we have to do enable setting, JSS Tracking we have more control for collecting analytic data like use event etc.

import { trackingApi } from '@sitecore-jss/sitecore-jss-tracking';const trackingApiOptions = {
host: config.sitecoreApiHost,
querystringParams: {
sc_apikey: config.sitecoreApiKey,
},
};
trackingApi
// note the events are an array - batching is supported
.trackEvent([{ eventId: 'Download' }], trackingApiOptions)
.then(() => console.log('Page event pushed'))
.catch((error) => console.error(error));

Note: Because Sitecore’s session tracking is cookie-based, it is important to pass browser cookies to both API.

--

--

No responses yet