Table of Contents

Using the RealTimeContainerScript.js to invoke real-time container APIs

Pega Marketing includes a sample JavaScript file which you can use to invoke real-time container APIs. The webwb/RealTimeContainerScript.js script includes a service controller object which has methods that invoke the Container APIs.

To use this script, do the following steps:

  1. Download and copy the JavaScript file to your web directory.
  2. Include the file in your web content.
    For example, include the following line: <script src="https://community.pega.com/realtimecontainerscript.js" />
  3. Instantiate the service controller object.
    For example: var nbamServiceCtrl = getNBAMServiceControl();
    To invoke a container with the V2 service, instantiate:
    var nbamServiceCtrl = getNBAMServiceControl()("V2");
    To invoke multiple containers with the V2 service, instantiate:
    var nbamServiceCtrl = getNBAMServiceControl()("V2", true);
  4. Initialize the service controller object using one of the following mechanisms.
    1. Directly update serverHostName and serverPort in realtimecontainerscript.js, as shown in the snippet below. When using this mechanism, the instantiation of the service controller initializes the controller using these values.
      var serverHostName = "localhost";var serverPort = "8080";
    2. Invoke the initialize method on the service controller after instantiating it.
      For example: nbamServiceCtrl.initialize(window.location.hostname, window.location.port);
  5. Invoke the desired API using the corresponding service controller method.
    Service API JavaScript Method Method Parameters
    Container getOffers customerID, containerName, channel, previousPage, currentPage, callback
    V2 Container loadOffers jsonObj, methodType, callback
    CaptureWebImpression captureSingleWebImpression containerID, customerID, offerID, issue, group, interactionID, callback
    CaptureWebResponse captureWebResponse containerID, customerID, offerID, issue, group, interactionID, outcome, behavior, channel, direction, callback
    CaptureResponse captureResponse containerID, customerID, offerID, issue, group, interactionID, outcome, behavior, channel, direction, callback
    CapturePaidResponse capturePaidClickResponse CustomerID, ExternalAudienceId, ReferrerUrl, Utm_medium, callback
Suggest Edit

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.