Real Time Engagement Scoring

Prev Next

Availability : Customers part of our Early Adopter Program for this feature.

Real time Engagement Scoring triggers a fresh behavioral score the moment a meaningful event activity occurs. The score reflects the lead’s cumulative weighted engagement over the past 90 days, not just the single event that triggered the calculation and writes directly back to the matching Salesforce Lead record within minutes. Sales reps see an up-to-date engagement score in Salesforce without any manual action.

This Scoring targets a end-to-end latency of 10 minutes - meaning scoring requests complete from trigger receipt to Salesforce Lead writeback within 10 minutes under normal operating conditions.

The Solution

How it works - High Level Flow

TRIGGER

Lead completes a qualifying product action

Marketo or Salesforce Trigger fires an API call to HG Insights

>>

SCORE

HG Insights fetches 90-day activity and scores the contact

Same behavioral model as nightly batch, Marketo  + Salesforce events

>>

WRITEBACK

Score written to Salesforce Lead record automatically

Score (0-100), Segment, Driving Signals updated within seconds

What Gets Written to Salesforce

Once scored, the fields are updated on the Lead record matching the provided email. The Salesforce fields updated can be found in Integrations → Push configuration.

For example, the typical fields in your Salesforce Sync will be:

Salesforce Field

Description

Likelihood to Buy Score (0-100)

Behavioural score (0-100) reflecting 90-day cumulative engagement

Likelihood to Buy Segment

Segment label (e.g. very high, high, medium, low)

Likelihood to buy Signals

Driving signals that contributed to the score

No Heavy Lifting on Your End: Your only integration touchpoint is configuring a trigger - either a Marketo or a Salesforce  Trigger. HG Insights handles all data fetching, scoring logic, and Salesforce writeback.

Works Like Batch Scoring

The HG Insights fields mapped in your existing batch sync are used for fast lane scoring automatically. No changes to your existing field Mapping are needed.


Rate Limits

Limit Parameter

Value

Default rate limit

5 requests / minute per tenant

Burst allowance

Up to 10 requests in a single minute (occasional spikes only)

Queue behaviour

Requests over the limit are queued, not dropped

Recommended use

High-intent events only — form fills, key page visits, status changes

Not recommended for

Bulk re-scoring, every lead update, scheduled batch triggers

How it works - High Level Flow

Step 1: Generate an API Key

  1. Login to admin.hginsights.com as an Administrator

  2. Navigate to Settings→ API Key

  3. Select Create API Key, Keys follow the format

    hg_v2_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  4. Store the key securely - it is used in Authorization header for every scoring request


Step 2: Verify Salesforce Lead field names

  1. Log in to admin.hginsights.com and navigate to Integrations > Salesforce.

  2. Click Push Settings and select the Salesforce Lead Fields tab.

  3. Confirm the three Engagement fields are mapped to your desired Salesforce Lead fields:

Settings page showing Salesforce lead field mappings and push configuration options.

Action Required: If these fields do not exist on the Lead object in your Salesforce org, your Salesforce administrator will need to create them as custom fields before testing the writeback.


Step 3: Setup your Trigger

Marketo Trigger

Setting up Marketo Webhook Trigger - Using Webhooks + Smart Campaigns

  1. Create Webhook

Navigate to Admin → Webhooks → New Webhook and fill in the fields as shown below.


Webhook configuration for HG Insights, detailing request type and template body.

Add the Authorization header — click Edit Request Headers inside the webhook

Request headers for API authorization and content type in JSON format.


  1. Create a Smart Campaign: Marketing Activities —> New Smart Campaign

Create a new Smart Campaign (e.g. "HG - Real-Time Score Trigger") and open the Smart List tab. Add a trigger that corresponds to the qualifying product action. The most common triggers are shown below.

Trigger

When to Use

Recommended Filter

Fills Out Form

Contact submits a high-intent form (demo request, pricing inquiry)

Form Name → contains → [form name]

Visits Web Page

Contact views a key product or pricing page

Web Page → is → [page URL]

Clicks Link in Email

Contact clicks a CTA in a nurture or product email

Link → contains → [URL fragment]

Data Value Changes

A lead field reaches a threshold (e.g. product score > X)

Attribute: [field], New Value: [value]

Triggers and filters for contact scoring in a marketing automation system.


3. Add a Flow Step: Flow tab —> Call Webhook

Flow steps for calling a webhook and live scoring process overview.

Once the flow is configured, click Activate Campaign. The campaign is now live.

Marketo treats any 2xx response as success. The HG Insights API returns HTTP 202 Accepted immediately, the actual scoring happens asynchronously in the background. Marketo will log the call as successful. The Salesforce Lead record is updated with the new real-time engagement score.

Salesforce Trigger - 2 Options

Option 1 : Salesforce Flow + HTTP Callout

Step 1  —  External Credential

Where: Setup  →  Security  →  Named Credentials  →  External Credentials tab
Who: Salesforce Administrator  |  Do once — required for all users of the integration

The External Credential stores your HG Insights API key encrypted at the Salesforce platform level. It is never visible in code, Flow definitions, or admin views after saving.

1.1 Create the External Credential

  1. Go to Setup  →  Security  →  Named Credentials.

  2. Click the External Credentials tab.

  3. Click New and fill in the fields below.

  setup.salesforce.com / Security / Named Credentials / External Credentials / New

Setup  >  Named Credentials  >  External Credentials  >  New External Credential

Label

HG Insights API

Name

HG_Insights_API

Authentication Protocol

Custom

Description

HG Insights Fast Lane Scoring — API key stored as Named Principal

Click Save. You land on the External Credential detail page.

1.2 Add the API Key as a Named Principal

On the External Credential detail page, scroll down to Principals and click New.

  setup.salesforce.com / Security / Named Credentials / External Credentials / HG_Insights_API / Principals / New

Setup  >  ...  >  HG_Insights_API  >  Principals  >  New Principal

Parameter Name

BearerToken  (no space — exactly as shown)

Sequence Number

1

Identity Type

Named Principal

Under Authentication Parameters click Add, then set:

Name:     Authorization

Value:    Bearer hg_v2_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  (your full key with 'Bearer ' and a space before it)

Click Save. The token is now encrypted. It cannot be retrieved after saving.

Common mistakes on this step

Parameter Name typed as 'Bearer Token' with a space — must be 'BearerToken' (no space)

Value contains only the key with no 'Bearer ' prefix — must be: Bearer hg_v2_xxxx...

Authentication Parameters section left empty — the Name and Value fields inside it must be filled

Wrong Identity Type selected — must be Named Principal
Do not use Custom Metadata (CMDT) to store the API key
CMDT Text fields are not encrypted and are visible to every Salesforce admin.
The External Credential Named Principal encrypts the token at the platform level.
Never hardcode the key in Apex or Flow definitions either — it appears in version control and logs.

Step 2  —  Named Credential and Custom Header

Where: Setup  →  Security  →  Named Credentials

Who: Salesforce Administrator  |  Do once


2.1 Create the Named Credential

The Named Credential defines the API base URL and references the External Credential. Apex and Flow reference it by the name HG_Insights_API.

  1. Still on the Named Credentials page, click the Named Credentials tab.

  2. Click New

  3. Complete the fields as shown and click Save.

  setup.salesforce.com / Security / Named Credentials / New

Setup  >  Named Credentials  >  New Named Credential

Label

HG Insights API

Name

HG_Insights_API

URL

https://api.hginsights.com

External Credential

HG_Insights_API

Generate Authorization Header

Checked

Allow Merge Fields in HTTP Header

Checked

Allow Merge Fields in HTTP Body

Checked

URL field is the base domain only — no path

  • Correct:   https://api.hginsights.com

  • Wrong:     https://api.hginsights.com/data-api/v2/scoring/behavioral/live

  • Wrong:     https://https://api.hginsights.com  (double https causes 500 Squid proxy error)

  • The path /data-api/v2/scoring/behavioral/live goes in the Flow HTTP Callout action, not here

2.2 Add the Authorization Custom Header

With Custom authentication protocol, Salesforce does not automatically send the Authorization header unless you explicitly add it as a Custom Header. This is a required step that is easy to miss — without it the API returns 401 Unauthorized.

  1. Go to Setup  →  Named Credentials. Click HG Insights API.

  2. Scroll down to Custom Headers and click New.

  3. Fill in the fields as shown and click Save.

  setup.salesforce.com / Security / Named Credentials / HG_Insights_API

Setup  >  Named Credentials  >  HG Insights API  >  Custom Headers  >  Create Custom Header

Name

Authorization

Value

Bearer hg_v2_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Sequence Number

1

Step 3  —  Remote Site Setting

Where: Setup  →  Security  →  Remote Site Settings

Who: Salesforce Administrator  |  Do once

Salesforce blocks all outbound HTTP calls to unlisted domains even when using a Named Credential. The HG Insights API domain must be explicitly added here.

  1. Go to Setup  →  Security  →  Remote Site Settings and click New Remote Site.

  2. Complete the fields as shown and click Save.

  setup.salesforce.com / Security / Remote Site Settings / New

Setup  >  Remote Site Settings  >  New Remote Site

Remote Site Name

HG_Insights_API

Remote Site URL

https://api.hginsights.com

Active

Checked

Disable Protocol Security

Unchecked (leave default)

Step 4  —  Permission Set for Credential Access

Where: Setup  →  Users  →  Permission Sets

Who: Salesforce Administrator

Salesforce requires explicit permission set access to use an External Credential — even for System Administrators. Without this step the Flow fails with: 'We couldn't access the credential(s).'


This step is easy to miss

Even if you are a System Administrator and created the External Credential yourself,

Salesforce still requires a Permission Set assignment to USE the credential at runtime.

This is Salesforce's security model for External Credentials — it cannot be bypassed.

4.1 Create a new Permission Set

  1. Go to Setup  →  Users  →  Permission Sets.

  2. Click New at the top of the list. (Do not click 'Create New View' — that is a different action.)

  3. Fill in:

Label:     HG Insights API Access

API Name:  HG_Insights_API_Access  (auto-fills)

License:   --None--

  1. Click Save. You land on the Permission Set detail page.

4.2 Enable External Credential Principal Access

  1. On the Permission Set detail page, scroll down and click External Credential Principal Access.

  2. Click Edit.

  3. Move HG_Insights_API - BearerToken from Available to Enabled.

  4. Click Save.

4.3 Assign the Permission Set to your user

  1. Go to Setup  →  Users  →  Users and click on your user name.

  2. Scroll down to Permission Set Assignments and click Edit Assignments.

  3. Move HG Insights API Access to Enabled.

  4. Click Save.

Section 5  —  Build the Record-Triggered Flow (This is an Example, details will depend on Customer’s trigger workflow)

5.1 Create a new Record-Triggered Flow

  1. Go to Setup  →  Process Automation  →  Flows.

  2. Click New Flow.

  3. Select Record-Triggered Flow and click Create.

5.2 Configure the Start element

  1. In the Object field type Lead and select Lead (API name: Lead). This is the standard Salesforce object. Do not select custom objects like Gong__Related_Lead__c or LeanData objects.

  2. Set Trigger to: A record is created or updated.

  3. Set Condition Requirements to: All Conditions Are Met (AND).

  4. Add Condition:

Field:     Status

Operator:  Is Changed

Value:     leave blank — Is Changed does not require a value

  1. Set When to Run the Flow for Updated Records to: Only when a record is updated to meet the condition requirements. This prevents the flow from firing on every single Lead update.

  2. Set Optimize the Flow for to: Actions and Related Records.

  3. Click Done.

5.3 Add a Decision element — Email guard

Before calling the API, add a Decision element to skip any Lead with a blank Email field. This prevents 400 Bad Request errors from the API.

  1. Click the + button below the Start element on the canvas.

  2. Select Decision.

  3. Set Label to: Email Not Blank

  4. Under Outcomes set Outcome Label to: Has Email

  5. Add Condition:

Resource:  {!$Record.Email}

Operator:  Is Null

Value:     {!$GlobalConstant.False}

  1. Click Done. The Has Email path connects to Step 5.4. The default path (no email) has no connection — the Flow ends silently for those records.

5.4 Add the HTTP Callout action

Add the action that calls the HG Insights API. This must be created using New HTTP Callout inside Flow Builder.

  1. Click the + button below the Has Email outcome path.

  2. Select Action.

  3. In the search box type HTTP Callout and select New HTTP Callout.

  4. On Step 1 of the wizard, fill in:

  flow.salesforce.com / Builder / Add Action / New HTTP Callout — Step 1

Flow Builder  >  Add Action  >  New HTTP Callout

Label

HG Insights Real Time Scoring

Method

POST

Named Credential

HG Insights API  (select from dropdown)

URL

https://api.hginsights.com  (auto-filled from Named Credential — read only)

URL Path

/data-api/v2/scoring/behavioral/live

URL Path vs URL field

The URL field (read-only) comes from the Named Credential and shows the base domain: https://api.hginsights.com. The URL Path field is where you type the endpoint path. Together they form the complete URL: https://api.hginsights.com/data-api/v2/scoring/behavioral/live


5.5 Define the request body

On the Set Request Body screen, paste a sample JSON body so Salesforce can infer the data structure.

Paste the following into the Sample JSON Request box:

JSON — SAMPLE REQUEST BODY

{

  "email": "test@example.com",

  "source": "salesforce"

}

Click Review. The Data Structure panel should show email (String) and source (String).

Click Next.

5.6 Connect and save the HTTP Callout

On the Connect with Sample Response screen, Salesforce makes a live test call to the API.

Click Connect.

You should see Status Code: 202 in the Response panel. This is correct — the API accepted the request.

Option 2: Salesforce Apex Trigger

1. Remote Site Settings  -  Setup > Security > Remote Site Settings

Salesforce blocks all outbound HTTP calls to unlisted domains. Add the HG Insights API domain before writing any Apex code.

  1. Go to Setup > Security > Remote Site Settings.

  2. Click New Remote Site.

  3. Fill in the fields below and click Save.

New Remote Site settings in Salesforce with API details and description provided.

2. Named Credential  -  Setup > Security > Named Credentials

A Named Credential stores the endpoint securely and is referenced in Apex by name, keeping credentials out of code.

  1. Go to Setup > Security > Named Credentials.

  2. Click New (Legacy) and fill in the fields below.

  3. Set Authentication Protocol to No Authentication - the Bearer token is passed as a custom header in Apex.

  4. Click Save.

New Named Credential setup for HG Insights API with URL and authentication details.


3. Apex Callout Class  -  Developer Console > New Apex Class

Create a new Apex class named HGInsightsLiveScoring. The @future(callout=true) annotation is required - Apex triggers cannot make synchronous HTTP callouts.

Apex code snippet for triggering live scoring via API in Salesforce.


4. Apex Trigger on Lead  -  Developer Console > New Apex Trigger

Create a trigger named HGInsightsScoringTrigger on Lead. Update isQualifyingStatus to match Customer’s Lead lifecycle stage values.


Apex code snippet for handling lead updates and deduplication in Salesforce.

Code snippet demonstrating lead scoring and email processing logic in a programming context.

Bulk Safety

The trigger collects emails in a Set<String> before firing callouts, so bulk Lead updates result in at most one API call per unique email. The @future method enforces one callout per invocation - this pattern is governor-limit safe.


Endpoint

POST https://api.hginsights.com/data-api/v2/scoring/behavioral/live

Request Body

Field

Type

Required

Description

email

string

Yes

Email address of the contact to score

source

string

System that triggered the request. Accepted values: salesforce, marketo

{
  "email": "user@example.com",
  "source": "salesforce"
}

Response

The endpoint is asynchronous. It returns 202 Accepted immediately — the score is not in the response body. Processing happens in the background: the contact's activity over the past 90 days is fetched, scored, and the result is written to the matching Salesforce Lead record automatically. No further action is required on your end.

Table displaying HTTP status codes and their corresponding meanings for API responses.