1
votes

I've just started working with Sitecore 9.1 JSS. From an external site, I make a RESTful API call to a Sitecore item like

http://site/sitecore/api/layout/render/jss?item=/&sc_apikey={KEY}

I created a campaign and invoked the above with the parameter:

https:/site/?sc_camp=<campaignid>&sc_lang=en

When I view campaigns in the Experience Analytics dashboard, no campaigns show up. (I did reindex)

I read this article: https://jss.sitecore.com/docs/fundamentals/services/tracking and also added the patch file as stated:

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

What am I missing? How do I trigger campaigns (and even goals) using Sitecore 9.1 JSS?

1

1 Answers

0
votes

I pulled an answer from this blog by Gary Wenneker:

Deploying the marketing definitions

Before we're able to trigger an event we have to deploy the marketing definitions. This is done from the control panel (Dashboard -> Control Panel). Click on the Deploy marketing definitions link. This will open a window with all the marketing definitions. Select them all and click Deploy. This might take about 15 minutes to run so don't think your system renders unresponsive and please don't be impatient :-)

Sitecore JSS Tracking API

The Tracking API can track several things by making a request to the Sitecore Layout Service. It accepts an array of specific types (with their properties)

const trackingApiOptions = {
    host: config.sitecoreApiHost,
    querystringParams: {
        sc_apikey: config.sitecoreApiKey, 
    }, 
    fetcher: dataFetcher
}; 

const track = (event: string) => {
    return function (dispatch: any, getState: any) {
        trackingApi
            // note the events are an array - batching is supported
            .trackEvent([{ eventId: event }], trackingApiOptions)
            .then(() => {
                dispatch(artistSearchedClickedRequest);
            })
            .catch((error: any) => console.error(error));
    }
}

The Tracking API Options object will provide the host, the Sitecore API key (by query string) and a data fetcher. This data fetcher will be a simple implementation of Axios but feel free to use whatever implementation you want:

import axios from "axios";

export function dataFetcher(url, data) {
  return axios({
    url,
    method: data ? 'POST' : 'GET',
    data,
    withCredentials: true,
  });
}