As per link JSS Personalization, In a JSS site, there are several paths to collecting analytics like via JSS Tracker and Layout Service.

Which one is better suite for this purpose?

2 Answers 2


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:

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

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,

  // 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.


If you are talking about a JSS Website which use the Layout Services. Then Analytics Via Layout Service is the most logical way. No additional code is required, and marketers can set for example a goal in Sitecore. Instead of a developer having to do that.

But both JSS Tracker and Layout Services have there one usage, because some thing are not going through the layout services. Think about GraphQL, cached in app, custom api's. or setting goals and event on places where that is not possible or desirable to do by content editors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.