Miscellaneous Ramblings on Hacking

July 30, 2010

Unica Interact via SOAP – How To

Filed under: .Net, Unica — Zack Bethem @ 9:50 pm

Background

Unica Interact extends Unica’s Campaign Suite for real-time offer management. If you want a full background of what it can offer, I’d suggest a read from Unica’s site. Here I’ll be discussing how to get started for some real basic integration. First, what you’ll need:

  • Unica’s v7 demo image or access to a Unica Interact implementation
  • Visual Studio 2008 (C# Express should work)

Interact Setup

When using the VMWare demo image provided, most of this is setup as part of the image. As an overview, however, I’ll review the following steps:

  1. Interactive Channel
  2. Session
  3. Assigned Campaign Offers and Ratings

Interactive Channel – Insurance

I’ll be using the already defined interactive channel Insurance. This is part of the Unica v7 demo image available to their partners. This interactive channel represents a website for an Insurance company and is defined with two zones, each with a single interaction point. One for home page landings, which would be the assumed landing page a user would see. Second, a signup page where a user would sign in based on existing credentials and/or register for first time use.

image

Interactive Session

From within the Interactive Channel summary tab, click on the related session Insurance. This will show the interactive session and its associated flowchart into focus for review.

image

Reviewing the associated flowchart, we see a simple segmentation of the incoming individual based on their related FICO score. Examining the process box FICO Score, the segmentation is as follows:

Low FICO Score Score < 200
Med FICO Score 200 < Score < 400
High FICO Score Score > 400

image

Lastly, examining the interaction process box Indiv_Id Profile the expected meta data for a session is shown along with the expected Audience. This will come into play later when the API initiates an interact session. For now, note that the audience level is Individual and the associated key is Indiv_Id. Also note the Score attribute in the record’s metadata used above for segmentation purposes.

image

Interactive Campaign

The last piece of the Interact puzzle is the associated interact campaign. Here is where the associated offers are defined by segment. I won’t go into the specifics as there is a complete User’s Guide for that, but here is where we can rank our offers. Note that some of the offers listed have expired, which is why they will not be shown later during the coding exercise. Also note that we have some offers tied directly to a given zone and that the offers have an associated ranking for presentation purposes.

image

Visual Studio Setup

With the review of the interact setup out of the way, it’s time prepare the VS environment for some coding. I’m using C# for this exercise which will limit me to using SOAP. Unica warns that the best performance is achieved using their interact_client.jar, but 1) I’m playing and 2) I’m not concerned with performance right now and 3) C# and .jar wouldn’t work to well and 4) I like C# more that I like java.

Import the WSDL

The WSDL for Interact can be found under:

<Affinium_Home>\Interact\conf\InteractService.wsdl

Be sure to use the file from your installation as a version incompatibility could exist!

Once you have the WSDL downloaded, you can build a DLL out of it by doing the following steps:

  1. As administrator, open a Visual Studio command prompt. This is different from just a normal DOS prompt as it has environment settings. The link is in the start menu under the Visual Studio 2008 folder.
  2. Using the wsdl.exe utility, generate a C# Class
    wsdl /l:CS /protocol:SOAP \InteractService.wsdl
  3. Compile the proxy class as a DLL
    csc /t:library /r:System.Web.Services.dll /r:System.Xml.dll InteractService.cs

Visual Studio C# Console Program

Add a InteractService.DLL Reference

Create a new C# Console program. Once the project structure is created, we’ll reference the DLL that was compiled from above. Once does this by Right-Clicking on the Reference folder in the Solution Explorer window and opting for Add Reference..

image

Build a Helper Class

I created a helper class in my code. The class is basic as potatoes, but it allows for the quick definition of NameValuePairs. These name-value pairs are important as they define the session’s record structure. Recall I mentioned that earlier in reviewing the session’s metadata.

    class InteractHelper
    {
        public NameValuePairImpl defineParm(string parmName, int valNumeric)
        {
            NameValuePairImpl parm = new NameValuePairImpl();
            parm.name = parmName;
            parm.valueAsNumeric = valNumeric;
            parm.valueDataType = "numeric";
            return parm;
        }
        public NameValuePairImpl defineParm(string parmName, string valString)
        {
            NameValuePairImpl parm = new NameValuePairImpl();
            parm.name = parmName;
            parm.valueAsString = valString;
            parm.valueDataType = "string";
            return parm;
        }
        public NameValuePairImpl defineParm(string parmName, DateTime valDate)
        {
            NameValuePairImpl parm = new NameValuePairImpl();
            parm.name = parmName;
            parm.valueAsDate = valDate;
            parm.valueDataType = "datetime";
            return parm;
        }
    }

Note in the code that there are three defined valueDataTypes for the NameValue pairs. These are:

  1. numeric
  2. string
  3. datetime

Build Console Main()

Keep in mind that this is just a glorified HelloWorld program with the intention to get you started. That being said, the bulk of the code is just thrown into the Main method in the Console Program’s class. Computer Science geeks can check their attitude at the door.

class Program
    {
        static void Main(string[] args)
        {

            InteractService _svc = new InteractService();
            //define the URI for the interact service listening for requests
            _svc.Url = "http://localhost:7001/interact/services/InteractService";

            //this will validate that we connect successfully upon receiving a version
            //number from the service
            getVersionResponse rVersion = _svc.getVersion();

            //setup the name-value pair(s) specifying the audience
            NameValuePairImpl IndivId = new NameValuePairImpl();
            IndivId.name = "Indiv_Id";
            IndivId.valueAsNumeric = 948;
            IndivId.valueDataType = "numeric";
            NameValuePairImpl[] initAudience = { IndivId };

            //setup the expected record structure for the session
            //these values don't have to have values, but the structure must
            //be defined!
            List<NameValuePairImpl> parmList = new List<NameValuePairImpl>();
            InteractHelper hlpr = new InteractHelper();
            parmList.Add(hlpr.defineParm("Score", 250));
            parmList.Add(hlpr.defineParm("HHold_Id", 372));
            parmList.Add(hlpr.defineParm("Head_Of_Hhold", "1"));
            parmList.Add(hlpr.defineParm("Score_Date", DateTime.Now));
            parmList.Add(hlpr.defineParm("Score", 300));
            parmList.Add(hlpr.defineParm("Age",30));
            parmList.Add(hlpr.defineParm("Income",35000));
            parmList.Add(hlpr.defineParm("Gender","M"));
            parmList.Add(hlpr.defineParm("Primary_Language","English"));
            parmList.Add(hlpr.defineParm("Marital_Status", "Single"));
            NameValuePairImpl[] sessionParms = parmList.ToArray();

            //start the interact session
            Response r = _svc.startSession("123456", false, true, "Insurance", initAudience, "Individual",
                sessionParms);

            //get available offers for the session
            Response rOffersAvail = _svc.getOffers(r.sessionID, "OnLineInsuranceHomePage", 5);

            //end the program
            Console.WriteLine("Done");
        }
    }

Summary

There are a few things that are important to review. These are represented in the images below.

First, the record structure defined within the Interact session should be in sync with the name-value pair array submitted when initiating an Interact session. This is shown in the image below while using my helper class for defining the Name-Value pair array.

Second, the offers received as part of the session match against the offer rules defined as part of the campaign for the given interaction zone. All offer rules from other campaigns are applied, such as expiration dates rendering an offer invalid. In the example below, I’m showing the program running in debug mode while watching variable assignment. Note that two offers are returned when making the getOffers() request for an individual with a FICO of 300 (aka. segment=MedFICO). The offers suggested are both active across all zones. The other two defined across the zones have both reached their expiration date. As a result, they are not returned.

And that is it. If you haven’t fallen asleep by now, congrats you made it. Hope it helps as you learn Interact. There are some tricky bits that make the getting started process bumpy. This post with the code samples should help you get going faster.

2 Comments »

  1. Great article. Is there anywhere to go for more info on Unica Interact? A few basic questions:

    1) Does interact support gathering context data (i.e. I ask a question to a customer during a dialog, and the answer is used by subsequent rules in determining which offer to display?)
    2) What if the context data is also used to update a predictive score of some sort, and the score result is used to determine what offer to display?

    Comment by jheld3 — August 26, 2010 @ 6:15 pm

    • Regarding #1) Yes. You would pass in the answer given via a name value pair. The value of which would be used in the session flowchart to take the appropriate decision branch and provide available offers.

      Regarding #2) There’s a External Callout API that can be used to retrieve the predictive score. Obviously you’d have to provide the hooks for the score calculator. Once the external callout is coded, it acts like a function. The result, of which, can then be stored in a derived field used within the session flowchart for logic purposes.

      Sadly, not much is out there on the internet regarding Unica products. Feel free to post info as you learn.

      Comment by Zack — August 31, 2010 @ 12:34 am


RSS feed for comments on this post. TrackBack URI

Leave a reply to jheld3 Cancel reply

Blog at WordPress.com.