var segmentProvider = {
name: "segmentProvider",
version: "1.0.0",
timeout: 1000,
callback: null,
provider: function (callback, params) {
...
It is important that your API request is also ready before the callback is called.
With the XMLHttpRequest this is for example onreadystatechange if (this.readyState == 4 && this.status == 200) is given.
After that you can write e.g. a cookie or something into the localStorage.
As I understand you, you want to read something from the localStorage.
var data = window.localStorage.getItem('td_segment') || '{}';
// here if necessary still regex etc.
Then call the callback
I would then output the segment as a ResponseToken. If this fits - you can then create your audience.
hope this helps you further
best regards