satellite.track complications in server side rendered react component?

saml9443

20-12-2019

We just launched a new site using a server side rendered react framework. In trying to send some _satellite.track objects (according what I have read to be best practices for a SPA), "_satellite" is undefined.

 

The developers then tried to use window._satelitte but from there they had an error where if a string wasnt passed to the tracker it threw another error so then it became stringified as a JSON object.

 

Does anyone know of issues with sending "_satellite.track" in React? Or are there other methods I am missing? 

 

Thanks!

Analytics launch react satellite.track server side

Accepted Solutions (0)

Answers (2)

Answers (2)

pabloc82923542

22-01-2020

As mentioned below a Direct call rule should do the trick.

 

Then depending on desired action first make rule "newPageload" in this case each firing a pageview.

 

Then make sure your SPA for each new state change(virtual page load) fires the rule:

 

_satellite.track("newPageload")

 

as long as app fires it when desired(up to you and devs) then teh action will fire your code.

 

2 things to watch out for:

 

Make sure satellite track and all elements are page ready before page bottom.

On some SPAs the initial load may double fire so you may need to suppress it.

 

 

harishkumar

22-12-2019

I am not sure of direct call rule working with react code or not but you can create customEvent() in react code and then using Launch core extension, create a event customEvent which will identify the custom event value and fire the launch rule on user action. 

 

Example Sample code for javascript is :

var viewEndCustomEvent = function viewEndCustomEvent() {
	  var event = new CustomEvent('event-view-end');
	  var obj = document.querySelector("#spa");
obj.dispatchEvent(event); };