Solved

Reset call not working in JS SDK _cio.reset()

  • 13 July 2023
  • 1 reply
  • 97 views

I’m in the process of implementing the JavaScript SDK on our website through Google Tag Manager. I have the page, track, and identify working properly!

However, after a user logs out of my app I’m calling _cio.reset() (documentation) and I can’t get this to work. I also don’t understand how to troubleshoot this.

Here is the code (tag) I’m firing in GTM … is this code correct?

 

It appears to be firing properly where I want it (on the logout screen, which is confusingly named Sign In but doesn’t matter):
 


Here is what the detail of the fired tag looks like:

 

The problem is that, even after this tag fires, as I continue to browse the website, the activity (page views, etc) continues to be tracked and associated to a known person in Customer.io (the person who was identified previously) so Customer.io appears to not be “accepting” the  _cio.reset() call -- shouldn’t future activity after _cio.reset() is called show up in Customer.io as anonymous activity?

The only way I can think to troubleshoot this is looking at the cookies stored. Both before and after the reset is called, there’s still a _cioid cookie showing up. Should this cookie go away automatically after _cio.reset() is called? Looking for help knowing how to debug this.
 


Thanks!

icon

Best answer by Jordan 15 July 2023, 03:18

View original

1 reply

Userlevel 2
Badge

Hey @caseyschorr 

 

Just following up here to share the outcome of our discussion via email support.

 

The issue here was a result of the _cio.reset() call happening prior to the _cio object completing its initialization. The solution was to add a little extra JavaScript to delay the _cio.reset() call until _cio was initialized, like so:

 

<script type="text/javascript">
// Set an interval, if at the end of the interval, _cio.reset can be called, call it and clear the interval. Otherwise, continue checking for _cio to initialize.
var cioResetInterval = setInterval(function waitingForCIOInitialization(){
console.log("Attempting to clear identifier with _cio.reset function");
if (typeof window._cio != "undefined" && Array.isArray(window._cio) == false && typeof window._cio.reset == "function") {
console.log("Calling _cio.reset function");
_cio.reset();
clearInterval(cioResetInterval);
}
},500)
</script>

 

The script above does the following:

  1. First, sets an interval and assigns that interval identifier to the variable cioResetInterval.
  2. At the end of the first interval, (after roughly 500 milliseconds in this case) it will check  if typeof window._cio.reset == "function".
  3. If that evaluation is  true, it will call _cio.reset(). Otherwise, if that evaluation is  false, the script will cycle back to step 2. This will continue to repeat on the set interval until typeof window._cio.reset == "function".
  4. Finally, when typeof window._cio.reset == "function". The script will clear the interval, preventing it from continuing to run.

 

NOTE: You should take this JavaScript only as an example, if may not work for your specific needs. For instance you may want to limit the number of times it will retry before stopping its attempt to execute _cio.reset(). You might also want to speed up or slow down its interval (e.g. cutting down from a 500 milliseconds wait to only 100 milliseconds). You might also want to remove the console.log messages.

 

Hopefully this helps any other future travelers that stumble upon the same issue. 😊

Reply