Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

satellite.track complications in server side rendered react component?

Avatar

Level 2

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!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

 

 

View solution in original post

2 Replies

Avatar

Level 2

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); };

 

Avatar

Correct answer by
Community Advisor

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.