Welcome to Zuora Product Documentation

Explore our rich library of product information

Reference

This reference provides a script example for posting segments to an HTTP listener using BlueConic's code. It includes necessary headers and segment data formatting.

The script injected to the browser is based on the code example provided by BlueConic on this page.
<script>
(function postSegmentsWhenReady() {
       function postSegments() {
       var segments = window.blueConicClient.getSegments().map((el) => {
            return el.id
        });

       if (segments.length) {
          var retrieveSegmentsXhr = new (XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0');
          retrieveSegmentsXhr.open('POST', '/plugins/public/blueconic/segments', true);
          retrieveSegmentsXhr.setRequestHeader('Content-type', 'application/json');
          retrieveSegmentsXhr.withCredentials = true;
          retrieveSegmentsXhr.send(JSON.stringify(segments));
       }
    }

    if (typeof window.blueConicClient !== 'undefined' &&
       typeof window.blueConicClient.event !== 'undefined' &&
       typeof window.blueConicClient.event.subscribe !== 'undefined') {
       postSegments();
    } else {
    window.addEventListener('onBlueConicLoaded', function () {
       postSegments();
       }, false);
    }
})();
</script>
If you are creating your own script to POST segments to the HTTP listener, you should be able to use the script above as an example. Please remember to include:
  • A valid session ID for your user in the `Cookie` header, for example:
    Cookie: blaize_session=70635d53-b265-4156-bd8d-ec479a95dec5
  • Any segments that you retrieve from BlueConic should be included in the request body as a stringified JSON array of strings.