Install the widget

Add the widget with the paste-in snippet or start it from JavaScript, and what the client and adviser details you pass are used for.

Installing it#

The paste-in snippet#

The Quick start snippet covers most portals. The widget starts by itself when the tag has both data-integration-key and data-firm-id.

Keep id="nurture-embed-script" on the tag. The widget uses it to find its own settings, for example if your framework re-adds the tag later.

Starting it from JavaScript#

To pass the values in JavaScript instead, load the script without data-integration-key and data-firm-id. It then waits until you call init():

html
<div id="subcontext-nurture"></div>
<script id="nurture-embed-script" src="https://js.subcontext.com/nurture-latest.js"></script>
<script>
  window.SubcontextNurture.init({
    integrationKey: 'YOUR_WIDGET_KEY',
    firmId: 'YOUR_FIRM_ID',
    identityToken: 'SIGNED_PASS_FROM_YOUR_SERVER',
    consumer: { firstName: 'Priya', lastName: 'Sharma', email: 'priya@example.com', externalId: 'CLIENT-123' },
    advisor: { name: 'Sam Patel', externalId: 'ADVISER-7', email: 'sam@example.com' },
    container: '#subcontext-nurture'
  })
</script>

You can mix the two. Settings on the tag come first, and anything you pass to init() replaces them one field at a time (the consumer and advisor objects are merged field by field too). For example, you can put the key on the tag and pass the client in JavaScript.

  • If the tag already has the key and firm id, the widget has started by the time your script runs. Calling init(options) then restarts it with your options, the same as destroy() followed by init(options).
  • Calling init() again with the same options (equal values) leaves the widget as it is. An open form stays open, and only your callbacks are updated. Frameworks that call setup code twice, like React in strict mode, therefore don't rebuild it.
  • init() with no options does nothing while a widget is running or waiting.
  • If your portal uses Turbo (Hotwire), the widget re-attaches after each page change unless you called destroy().

The client and adviser details you pass#

What you pass What it's used for
Client details The contact the message goes to, and the conversation that follows in the firm's Subcontext account.
Adviser details Recorded with each message and with the terms acceptance. The adviser's name and email are used for notices about a trial account. With a signed pass, the adviser id from the pass is always the one used.
Reason, outcome and note, or your call note The brief the AI writes the first message from.
subcontext Background the assistant reads during the conversation. It is not put into the first message.

Call note#

If your portal already has a note from the call, pass it as draftNote. The form then skips the reason and outcome menus. The adviser picks a channel, and the note is used as the brief.

The note shows as text. Clicking it turns it into a text box, so the adviser can correct it. If they clear it, Generate is turned off until they write something. An empty or unreplaced value falls back to the menus. In a single-page portal, change or clear it with setConsumer's draftNote.

Background for the assistant#

subcontext can hold anything useful for the conversation, such as previous quotes or existing cover. The adviser can see it in the form under "What the assistant will know". It can be up to 64 KB as JSON.

In init(), pass the object itself. In a data attribute, pass JSON text. JSON for an object or a list is read as data. Anything else is kept as plain text.

html
<script id="nurture-embed-script" ...
  data-subcontext='{"previousQuotes":[{"provider":"Northbank Life","cover":250000,"termYears":25,"monthlyPremium":18.42}]}'></script>

Wrap the attribute in single quotes (or write &quot; for each double quote) so the quotes inside the JSON survive.

Picking up after a page refresh#

The adviser's work in progress (the form, client details they typed, drafts and edits) is kept in the browser tab's session storage. If they reload the page, they pick up where they left off. Once a message is sent, the next visit starts fresh.

The saved copy is named with a one-way digest, so nothing readable about the client is in its name. Sending, Done, Cancel (in docked mode) and setConsumer clear it. If the browser blocks storage, the widget starts fresh each time.

Stuck, or something missing?

Get in touch and a person on the team will help.

Contact us