Owns the journey/funnel engine: creates and stores Funnel (journey) definitions, matches inbound platform events against a Funnel's entry points and goals, creates and advances Lead records through a Funnel's nodes, and fires the lead lifecycle events (created, updated, closed, cancelled) that other apps listen for. Registered as an EventListener, it receives platform events such as email delivery, subscription, shopping cart and reward events and translates the relevant ones into FunnelEvent instances that drive journeys forward. Reached from Java via C(FunnelManager.class), and from the funnels admin UI and journey automations.

Group: Managers

Implements: EventListener


Properties

PropertyReturnsDescription
currentAttributesMap<String,Object>A thread-local scratch map that is reset at the start of each funnel event and shared by the event's automation checks and node actions, so they can pass data to each other without threading it through method parameters.
funnelActionTypesList<FunnelActionType>The action types available for use in journey automations, collected from every active JourneyBuilderApplication.
funnelsMap<String,Funnel>All funnels defined in the current tenant organisation, keyed by funnel repository name.
funnelTriggerTypesList<FunnelTriggerType>The trigger types available for use in journey automations, collected from every active JourneyBuilderApplication.
nonHiddenFunnelsMap<String,Funnel>All funnels in the current tenant organisation whose "hidden to sales" flag is not set, sorted by name.
scoringFactorTypesMap<String,EngagementScoringFactorType>The engagement scoring factor types available for use in journeys, as registered with LeadScoringService.

Methods

recreateEvent(String urn, Map<String,Serializable> properties) · registerListener(FunnelEventListener l) · getCurrentAttributes() · createJourney(String newName, String json) · getFunnelRepo(Organisation org, String name) · getFunnelRepo(String name) · findFunnelsInCategory(RepositoryCategory category) · getFunnel(Organisation org, String name) · getFunnel(Lead lead) · getLeadRoleDefs(Lead lead) · getLeadRoleDefs(Funnel funnel) · findLeadRoleDef(Funnel funnel, String roleKey) · getFunnel(String funnelName) · getFunnel(FunnelRepository r) · getFunnel(Branch b) · getFunnel(Long funnelId) · getFunnel(Branch b, boolean useCache) · getFunnelSource(Branch b) · save(Funnel funnel) · getFunnels() · onFunnelEvent(FunnelEvent funnelEvent) · onFunnelEvent(FunnelEvent funnelEvent, boolean throwExceptions) · calcRelativeToDate(Lead lead, Goal enteringGoal, Date defaultDate) · findExistingLeads(FunnelRepository funnel, Profile cust, String trackingId) · updateLead(Lead lead) · createLead(FunnelRepository funnelRepo, String source, Profile cust, String description, Profile assignedTo, Organisation assignedToOrg) · createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, String initialGoal, Map<String,String> fieldsValues) · createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, Profile assignedTo, String initialGoal, Lead sourceLead, Map<String,String> fieldsValues, Asset asset) · createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, String initialGoal) · createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, Profile assignedTo, String initialGoal) · createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, Profile assignedTo, String initialGoal, Lead sourceLead) · findMatchingTester(Funnel funnel, Lead lead) · getAllFields(Funnel f) · findFields(Funnel f, int version) · extraFieldMeta(Funnel f, String fieldId) · findFieldValue(String fieldId, Lead lead, Funnel f) · loadRules(String source) · getScoringFactorTypes() · getEngagementScore(Lead lead) · calcEngagementScore(Lead lead) · recalcAllEngagementScores(Consumer<String> progressCallback) · recalcEngagementScores(FunnelRepository repo, Consumer<String> progressCallback) · countOfLeadsToStart(Funnel funnel, String startNode) · profilesToStart(Funnel funnel, String startNode) · startLeads(Funnel funnel, String startNode) · startLeads(Funnel funnel, String startNode, List<Long> startProfileIds) · getNonHiddenFunnels() · getFunnelExtraFields(String journeyName) · getFunnelTriggerTypes() · findAvailOutcomes(Task task) · getFunnelActionTypes() · setFieldValue(Lead leadToUpdate, String fieldName, Object value) · countActiveLeads(FunnelRepository funnelRepository)

recreateEvent(String urn, Map<String,Serializable> properties)

Returns: FunnelEvent

Rebuilds a FunnelEvent from a URN of the form "prefix:appId:objectId", by asking the app named in the URN to recreate the event for the given object id and properties. Used to reconstruct an event from a stored reference rather than replaying it live.

ParameterDescription
urnthe event reference; its second colon-separated part must be the source app id and its third part the object id
propertiesextra properties to attach to the recreated event

registerListener(FunnelEventListener l)

Returns: void

Registers a listener that is notified of every FunnelEvent processed by this manager, in addition to the manager's own journey matching logic. Used by other apps to observe funnel activity without duplicating the event dispatch logic.

ParameterDescription
lthe listener to add

getCurrentAttributes()

Returns: Map<String,Object>

A thread-local scratch map that is reset at the start of each funnel event and shared by the event's automation checks and node actions, so they can pass data to each other without threading it through method parameters.

createJourney(String newName, String json)

Returns: FunnelRepository

Creates a new journey (funnel) repository with the given name and stores the given JSON definition as its funnel.json file in the repository's live branch. Reports the creation to account telemetry.

ParameterDescription
newNamethe name of the new journey repository
jsonthe JSON definition of the journey to create

getFunnelRepo(Organisation org, String name)

Returns: FunnelRepository

Finds a funnel repository by name within the given organisation.

ParameterDescription
orgthe organisation to search
namethe funnel repository name to match

getFunnelRepo(String name)

Returns: FunnelRepository

Finds a funnel repository by name within the current tenant organisation.

ParameterDescription
namethe funnel repository name to match

findFunnelsInCategory(RepositoryCategory category)

Returns: List<FunnelRepository>

Finds all funnel repositories in the current tenant organisation that belong to the given category. If category is null, the funnel repositories that have no category are returned instead.

ParameterDescription
categorythe category to match, or null to find uncategorised funnels

getFunnel(Organisation org, String name)

Returns: Funnel

Finds the Funnel with the given name in the given organisation.

ParameterDescription
orgthe organisation to search
namethe funnel name to match

getFunnel(Lead lead)

Returns: Funnel

Finds the Funnel for the given lead's current branch, falling back to the funnel repository's trunk if the lead has no branch set. Uses the funnel cache, so this is efficient to call repeatedly while iterating over a list of leads.

ParameterDescription
leadthe lead whose funnel should be found; if null, null is returned

getLeadRoleDefs(Lead lead)

Returns: List<LeadRoleDef>

The full list of lead participant roles available for the given lead's funnel: the 4 system roles implied by Lead's legacy profile / organisation / assignedToOrg / assignedToProfile fields, plus any custom roles configured on the funnel itself.

ParameterDescription
leadthe lead whose funnel's roles should be listed

getLeadRoleDefs(Funnel funnel)

Returns: List<LeadRoleDef>

The full list of lead participant roles available for the given funnel: the 4 system roles implied by Lead's legacy fields, plus any custom roles configured on the funnel.

ParameterDescription
funnelthe funnel whose custom roles should be merged with the system roles; may be null

findLeadRoleDef(Funnel funnel, String roleKey)

Returns: LeadRoleDef

Finds a single role, by key, from the combined system and custom role list for the given funnel.

ParameterDescription
funnelthe funnel to search, may be null
roleKeythe role key to find

getFunnel(String funnelName)

Returns: Funnel

Finds the Funnel with the given name in the current tenant organisation.

ParameterDescription
funnelNamethe funnel name to match

getFunnel(FunnelRepository r)

Returns: Funnel

Gets the Funnel for the trunk branch of the given funnel repository.

ParameterDescription
rthe funnel repository to load the funnel from; if null, null is returned

getFunnel(Branch b)

Returns: Funnel

Gets the Funnel for the given branch, using the funnel cache.

ParameterDescription
bthe branch to load the funnel from

getFunnel(Long funnelId)

Returns: Funnel

Finds the Funnel with the given funnel repository id in the current tenant organisation.

ParameterDescription
funnelIdthe id of the funnel repository to load; if null, null is returned

getFunnel(Branch b, boolean useCache)

Returns: Funnel

Gets the Funnel for the given branch, optionally reading the funnel cache instead of parsing the branch's funnel.json file directly.

ParameterDescription
bthe branch to load the funnel from
useCachetrue to use the funnel cache, false to force a fresh parse of the funnel definition

getFunnelSource(Branch b)

Returns: String

Returns the raw JSON source of the funnel definition stored on the given branch. Intended for debugging rather than for regular use.

ParameterDescription
bthe branch to read the funnel definition from

save(Funnel funnel)

Returns: void

Saves the given Funnel as JSON back to its own branch, as the current user.

ParameterDescription
funnelthe funnel to save; its branch is resolved from funnel.getBranch()

getFunnels()

Returns: Map<String,Funnel>

All funnels defined in the current tenant organisation, keyed by funnel repository name.

onFunnelEvent(FunnelEvent funnelEvent)

Returns: void

Feeds a FunnelEvent into the journey engine: matches it against active funnels' entry points and existing leads, and advances any matching lead through its journey nodes. Any exception raised while processing an individual funnel is caught and logged rather than propagated.

ParameterDescription
funnelEventthe event to process

onFunnelEvent(FunnelEvent funnelEvent, boolean throwExceptions)

Returns: void

Feeds a FunnelEvent into the journey engine, as per onFunnelEvent(FunnelEvent), but lets the caller choose whether an exception raised while processing a funnel is propagated or just logged. Does nothing if the event, its organisation, or the funnels app is not active for that organisation. Notifies any registered FunnelEventListeners, checks automations for the event's related entity, then resolves the relevant leads (the lead already related to the event if there is one, otherwise every funnel whose entry points could match the event) and transitions each through its journey.

ParameterDescription
funnelEventthe event to process; if null, this method does nothing
throwExceptionstrue to rethrow an exception raised while processing an individual funnel, false to log and continue with the next funnel

calcRelativeToDate(Lead lead, Goal enteringGoal, Date defaultDate)

Returns: Date

Calculates the date that a goal's timeout should be measured from, by evaluating the goal's timeoutRelativeDateMVEL expression (an MVEL expression, or a kcode expression if it starts with the kcode template prefix). Returns defaultDate unchanged if the goal is null, has no relative-date expression, if a matching funnel tester is active for the lead, or if the expression evaluates to null.

ParameterDescription
leadthe lead the goal belongs to
enteringGoalthe goal whose timeoutRelativeDateMVEL expression should be evaluated
defaultDatethe date to fall back to if no relative date can be calculated

findExistingLeads(FunnelRepository funnel, Profile cust, String trackingId)

Returns: List<Lead>

Finds existing, non-deleted leads for the given funnel repository that match the given customer profile and/or tracking id, in the current tenant organisation.

ParameterDescription
funnelthe funnel repository to search
custthe customer profile to match; may be null
trackingIdthe tracking id to match; optional, may be null

updateLead(Lead lead)

Returns: Lead

Marks the lead as modified now, fires its update side effects (engagement score recalculation and lead-updated events), and saves it.

ParameterDescription
leadthe lead to update

createLead(FunnelRepository funnelRepo, String source, Profile cust, String description, Profile assignedTo, Organisation assignedToOrg)

Returns: Lead

Creates a new lead in the given funnel repository, entering it at the funnel's default entry point. Throws an exception if the funnel repository's funnel could not be loaded.

ParameterDescription
funnelRepothe funnel repository to create the lead in
sourcea free-text description of where the lead came from
custthe customer profile the lead is for; may be null
descriptiona description to record against the lead
assignedTothe profile the lead should be assigned to; may be null
assignedToOrgthe organisation the lead should be assigned to; may be null

createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, String initialGoal, Map<String,String> fieldsValues)

Returns: Lead

Creates a new lead in the given funnel, entering it at initialGoal (or the funnel's default entry point if initialGoal is blank), and sets the given field values on it.

ParameterDescription
fthe funnel to create the lead in
funnelRepothe funnel's repository
custthe customer profile the lead is for; may be null
initialGoalthe node id to enter the lead at, or blank to use the funnel's default entry point
fieldsValuesa map of field name to value to set on the new lead

createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, Profile assignedTo, String initialGoal, Lead sourceLead, Map<String,String> fieldsValues, Asset asset)

Returns: Lead

Creates a new lead in the given funnel, entering it at initialGoal (or the funnel's default entry point if initialGoal is blank), assigning it and linking it to a source lead and asset.

ParameterDescription
fthe funnel to create the lead in
funnelRepothe funnel's repository
custthe customer profile the lead is for; may be null
assignedTothe profile the lead should be assigned to; may be null
initialGoalthe node id to enter the lead at, or blank to use the funnel's default entry point
sourceLeadthe lead this new lead was created from; may be null
fieldsValuesa map of field name to value to set on the new lead
assetthe asset associated with the lead's creation; may be null

createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, String initialGoal)

Returns: Lead

Creates a new lead in the given funnel, entering it at initialGoal (or the funnel's default entry point if initialGoal is blank).

ParameterDescription
fthe funnel to create the lead in
funnelRepothe funnel's repository
custthe customer profile the lead is for; may be null
initialGoalthe node id to enter the lead at, or blank to use the funnel's default entry point

createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, Profile assignedTo, String initialGoal)

Returns: Lead

Creates a new lead in the given funnel, entering it at initialGoal (or the funnel's default entry point if initialGoal is blank), and assigns it.

ParameterDescription
fthe funnel to create the lead in
funnelRepothe funnel's repository
custthe customer profile the lead is for; may be null
assignedTothe profile the lead should be assigned to; may be null
initialGoalthe node id to enter the lead at, or blank to use the funnel's default entry point

createLead(Funnel f, FunnelRepository funnelRepo, Profile cust, Profile assignedTo, String initialGoal, Lead sourceLead)

Returns: Lead

Creates a new lead in the given funnel, entering it at initialGoal (or the funnel's default entry point if initialGoal is blank), assigns it, and links it to a source lead.

ParameterDescription
fthe funnel to create the lead in
funnelRepothe funnel's repository
custthe customer profile the lead is for; may be null
assignedTothe profile the lead should be assigned to; may be null
initialGoalthe node id to enter the lead at, or blank to use the funnel's default entry point
sourceLeadthe lead this new lead was created from; may be null

findMatchingTester(Funnel funnel, Lead lead)

Returns: FunnelTester

Finds the first funnel tester configured on the funnel whose match conditions apply to the given lead. Funnel testers are used to bypass normal timeout/due-date calculations while testing a journey.

ParameterDescription
funnelthe funnel whose testers should be searched
leadthe lead to match against

getAllFields(Funnel f)

Returns: List<Field>

The full list of fields available for use in this funnel: every field registered with FieldsService (version 1), plus any extra fields defined on the given funnel.

ParameterDescription
fthe funnel whose extra fields should be included; may be null

findFields(Funnel f, int version)

Returns: List<Field>

The full list of fields available for use in this funnel at the given field version: every field registered with FieldsService for that version, plus, for version 1 only, any extra fields defined on the given funnel.

ParameterDescription
fthe funnel whose extra fields should be included; may be null
versionthe field version to look up (see FieldsService)

extraFieldMeta(Funnel f, String fieldId)

Returns: ExtraField

Finds the metadata for an extra field, first checking the funnel's own extra field definitions and falling back to FunnelFieldsHelper's built-in field metadata.

ParameterDescription
fthe funnel whose extra fields should be searched
fieldIdthe field name to find metadata for

findFieldValue(String fieldId, Lead lead, Funnel f)

Returns: Object

Evaluates the value of a field for the given lead: a kcode template, a registered Field, a FunnelFieldsHelper built-in field, or one of the funnel's extra fields, in that order.

ParameterDescription
fieldIdthe field id, kcode expression, or field name to evaluate
leadthe lead to evaluate the field against
fthe lead's funnel, used to resolve extra fields

loadRules(String source)

Returns: Rules

Parses a query builder rules definition from JSON source, via the funnel cache.

ParameterDescription
sourcethe JSON source of the rules to parse

getScoringFactorTypes()

Returns: Map<String,EngagementScoringFactorType>

The engagement scoring factor types available for use in journeys, as registered with LeadScoringService.

getEngagementScore(Lead lead)

Returns: Float

The lead's already-calculated engagement score. Does not recalculate the score; use calcEngagementScore to compute a fresh value.

ParameterDescription
leadthe lead whose stored engagement score should be read

calcEngagementScore(Lead lead)

Returns: Pair<Float,String>

Calculates the lead's engagement score from scratch, based on its funnel's scoring factors.

ParameterDescription
leadthe lead to calculate the engagement score for

recalcAllEngagementScores(Consumer<String> progressCallback)

Returns: void

Recalculates the engagement scores of every active lead in every funnel in the current tenant organisation, reporting progress as it goes.

ParameterDescription
progressCallbackcalled with a human-readable progress message before each funnel repository is processed

recalcEngagementScores(FunnelRepository repo, Consumer<String> progressCallback)

Returns: void

Recalculates the engagement scores of every active lead in the given funnel repository, reporting progress as it goes.

ParameterDescription
repothe funnel repository whose leads' engagement scores should be recalculated
progressCallbackcalled with a human-readable progress message before each lead is processed

countOfLeadsToStart(Funnel funnel, String startNode)

Returns: int

Counts how many leads would be started if startLeads were called now for the given manual-initiation begin node, without actually creating any leads. Returns 0 if startNode is not a begin node leading to a ManualInitiationNode.

ParameterDescription
funnelthe funnel containing the begin node
startNodethe id of the begin node to check

profilesToStart(Funnel funnel, String startNode)

Returns: Set<Profile>

Finds which profiles would have a lead started for them if startLeads were called now for the given manual-initiation begin node, without actually creating any leads. Returns null if startNode is not a begin node leading to a ManualInitiationNode.

ParameterDescription
funnelthe funnel containing the begin node
startNodethe id of the begin node to check

startLeads(Funnel funnel, String startNode)

Returns: int

Starts a lead for every matching profile at the given manual-initiation begin node. Equivalent to calling startLeads(funnel, startNode, null).

ParameterDescription
funnelthe funnel containing the begin node
startNodethe id of the begin node to start leads from

startLeads(Funnel funnel, String startNode, List<Long> startProfileIds)

Returns: int

Starts a lead for every matching profile at the given manual-initiation begin node, optionally restricted to a specific set of profiles. Skips a profile if it already has an existing lead and the begin node only allows one lead per profile. Does nothing and returns 0 if startNode is not a begin node leading to a ManualInitiationNode.

ParameterDescription
funnelthe funnel containing the begin node
startNodethe id of the begin node to start leads from
startProfileIdsif given, only profiles whose id is in this list are started; null starts every matching profile

getNonHiddenFunnels()

Returns: Map<String,Funnel>

All funnels in the current tenant organisation whose "hidden to sales" flag is not set, sorted by name.

getFunnelExtraFields(String journeyName)

Returns: List<ExtraField>

Finds the extra fields defined on the non-hidden funnel with the given name, in the current tenant organisation.

ParameterDescription
journeyNamethe funnel name to match

getFunnelTriggerTypes()

Returns: List<FunnelTriggerType>

The trigger types available for use in journey automations, collected from every active JourneyBuilderApplication.

findAvailOutcomes(Task task)

Returns: List<TaskOutcome>

Finds the possible outcomes for the task goal that the given task belongs to.

ParameterDescription
taskthe task to find outcomes for; may be null

getFunnelActionTypes()

Returns: List<FunnelActionType>

The action types available for use in journey automations, collected from every active JourneyBuilderApplication.

setFieldValue(Lead leadToUpdate, String fieldName, Object value)

Returns: void

Sets a field value on the lead, using the current Hibernate session. Equivalent to calling the static setFieldValue(leadToUpdate, fieldName, value, session).

ParameterDescription
leadToUpdatethe lead to update
fieldNamethe field name to set
valuethe value to set; if blank, this method does nothing

countActiveLeads(FunnelRepository funnelRepository)

Returns: long

Counts the active (not closed, cancelled or deleted) leads in the given funnel repository.

ParameterDescription
funnelRepositorythe funnel repository to count leads for
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.