This method returns a context of type AudienceFeedConnectorBaseInstanceContext or an extended context of type InstanceContext.
We recommend you to use the extended context in order to simplify the reuse of objects and variables in the plugin code.
The original context format contains the feed metadata and its properties.
ctx (AudienceFeedConnectorBaseInstanceContext)
The original format of the AudienceFeedConnectorBaseInstanceContext type is
Parameter
Type
Description
feed
AudienceSegmentExternalFeedResource
Represents the external feed resource for the audience segment.
feedProperties
PropertiesWrapper
Wrapper for properties associated with the feed, containing metadata and configurations.
With the object feed (AudienceSegmentExternalFeedResource) that represents the external feed resource for the audience segment:
Parameter
Type
Description
id
string
Unique identifier for the audience segment external feed.
plugin_id
string
Identifier for the plugin associated with the feed.
organisation_id
string
Identifier for the organization that owns the feed.
group_id
string
Identifier for the group to which the feed belongs.
artifact_id
string
Identifier for the specific plugin artifact related to the feed.
version_id
string
Version identifier for the feed, indicating its versioning.
selected_identifying_resources
IdentifyingResourceShape
optional
Optional array of identifying resources used for segment identification.
created_by
string
Optional identifier for the user that created the feed.
The extended context contains the feed metadata, the feed properties, plus a bunch of useful variables and objects.
instanceContext (InstanceContext)
Those are the variables and objects that extend the original context (AudienceFeedConnectorBaseInstanceContext).
Parameter
Type
Description
technicalConfig
TechnicalConfiguration
Configuration details for technical aspects.
loggerPrefix
string
A prefix for logging to identify the source of log messages.
segment
AudienceSegmentResource
The audience segment resource being processed.
properties
Properties
Plugin properties of the created feed.
credentials
Credentials
Credentials for external systems.
datamartConfig
DatamartConfiguration
Configuration specific to the datamart.
micsApiClient
MicsApiClient
Client for interacting with the MICS API.
partnerClient
PartnerClient
Client for interacting with the partner solution.
Code
There is only one input parameter feedId, but you must retrieve the context ctx at the beginning of the method code to extend it, like this:
Code example
onExternalSegmentCreation
This method checks wether the audience already exist on the partner platform, or if it must create it. In this last case, we create the audience.
request (ExternalSegmentCreationRequest, required): An object containing the details necessary for creating the segment. It is sent by the platform at the feed creation.
request object format:
Parameter
Type
Description
feed_id
string
The unique identifier of the feed
segment_id
string
The unique identifier of the segment related to the feed
datamart_id
string
The identifier for the datamart of the segment
context (InstanceContext, required): The context in which the feed creation is executed, containing various configuration and resource objects.
Check the instance context section to understand the format of the feed instance context.
You can find the extended context interface in the returns tab.
Return
Resolves to an object containing the status of the segment creation process, along with an optional message and visibility.
Establishing connection with segment on destination platform.
This method check the availability of the segment on the destination platform.
Also, through the instance context method, this onExternalSegmentConnection method may validate feed properties and selected identifying resources. It is not mandatory at this step as it was supposed to be done beforehand.
Input parameters
request (ExternalSegmentConnectionRequest, required): An object containing the details necessary for creating the segment. It is sent by the platform at the feed creation.
request object format:
Variable
Type
Description
feed_id
string
The unique identifier of the feed
segment_id
string
The unique identifier of the segment related to the feed
datamart_id
string
The identifier for the datamart of the segment
context (InstanceContext, required): The context in which the feed creation is executed, containing various configuration and resource objects.
Check the instance context section to understand the format of the feed instance context.
You can find the extended context interface in the returns tab.
Return
Resolves to an object containing the status of the segment creation process, along with an optional message and visibility.
This method sends the user identifiers (insertion or deletion) or prepares the payload to be sent to the partner platform.
Depending on the plugin output type, this method will have different roles and return different objects.
Single API calls (classic plugin)
This method sends the user identifiers (insertion or deletion) to the partner platform.
Batch API calls
This method inserts the user identifiers in the batch through the returned object - it can be for both insertion or deletion.
The batch will be sent to the partner platform through the onBatchUpdate method.
File delivery
This method inserts the user identifiers in the file through the returned object - it can be for both insertion or deletion.
Also, through the instance context method, this onUserSegmentUpdate method may again validate feed properties and selected identifying resources. It is not mandatory at this step again as it was supposed to be done beforehand.
Input parameters
request (UserSegmentUpdateRequest, required): An object containing the details necessary for creating the segment. It is sent by the platform at the feed creation.
request object format:
Parameter
Type
Description
feed_id
string
unique identifier for the feed associated with the user segment update
session_id
string
identifier for the session during which the update is being made
datamart_id
string
identifier for the datamart where the user segment resides
segment_id
string
unique identifier for the segment being updated
user_identifiers
UserIdentifierInfo[]
array of user identifiers from the segment to send to the partner platform
user_profiles
UserProfileInfo[]
array of user profiles from the segment to send to the partner platform
ts
number
timestamp indicating when the update request was created
operation
UpdateType
type of update operation being performed, indicating whether it is an add, remove, or modify operation
context (InstanceContext, required): The context in which the feed creation is executed, containing various configuration and resource objects.
Check the instance context section to understand the format of the feed instance context.
You can find the extended context interface in the returns tab.
Return (batch case)
Resolves to an object containing the batch of users identifiers to update on the segment destination platform.
This method is utilized to troubleshoot the feed using audience data from the partner platform.
Input parameters
request (TroubleshootActionFetchDestinationAudience, required): An object containing the details necessary for handling the troubleshoot.
Parameter
Type
Description
feed_id
string
The unique identifier of the feed
segment_id
string
The unique identifier of the segment related to the feed
datamart_id
string
The identifier for the datamart of the segment
action
enum['FETCH_DESTINATION_AUDIENCE']
context (InstanceContext, required): The context in which the feed creation is executed, containing various configuration and resource objects.
Check the instance context section to understand the format of the feed instance context.
You can find the extended context interface in the returns tab.
Return
Resolves to an object containing the status of the segment creation process, along with an optional message and visibility.
Data to be displayed in the troubleshooting section of the feed card. It must provide as much data as possible to compare identifiers received, stored and used by the partner platform
Code
Code example
Batching
This method is required if we batch the calls to the partner API or to send a flat file.
onBatchUpdate
Send the batched payload of user identifiers to the partner platform.
This payload is prepared by our platform thanks to the unitary calls to the onUserSegmentUpdate method.
Array of items (insertion/deletion) to be sent to the partner platform
ts
number
Timestamp indicating when the batch update request was created
context
AudienceFeedBatchContext
Context information relevant to the batch update process
We do not use this variable from this parameter.
context (InstanceContext, required): The context in which the feed creation is executed, containing various configuration and resource objects.
Check the instance context section to understand the format of the feed instance context.
You can find the extended context interface in the returns tab.
Return
Resolves to an object containing the status of the users identifiers sent to the destination platform, along with an optional message.
Promise<BatchUpdatePluginResponse>
BatchUpdatePluginResponse object format:
Parameter
Type
status
enum['OK' | 'ERROR' | 'RETRY']
message
string, optional
next_msg_delay_in_ms
number, optional
sent_items_in_success
number
sent_items_in_error
number
Code
Code example
Authentication
onAuthenticationStatusQuery
Check the authentication status of the connector. If the connector has no valid authentication, it must respond with a url to let the user authenticate through the desired method.
Input parameters
request (ExternalSegmentAuthenticationStatusQueryRequest): Request sent at authentication checking.
Parameter
Type
Description
segment_id
string, optional
Optional identifier for the segment being queried
datamart_id
string
Identifier for the datamart associated with the authentication status query
plugin_version_id
string
Identifier for the version of the plugin being used
user_id
string
Unique identifier for the user making the authentication status query
properties
PluginProperty[], optional
Optional array of properties related to the plugin for additional context
Return
Resolves to an object containing the status of the authentication, and the login url if not authenticated.
Status of the authentication process indicating success or
message
string, optional
Message providing additional information about the authentication
data
object, optional
Optional object containing additional data related to the authentication status
data object format:
Parameter
Type
Description
login_url
string, optional
Optional URL for the login page if authentication is
any key
string, optional
Additional properties can be included in this object as needed
Code
Code example
onAuthentication
Handle the redirection from the partner authentication flow and authenticate the connection within mediarithmics.
Input parameters
request (ExternalSegmentAuthenticationRequest): Request forwarded from the partner response after authentication on their
Parameter
Type
Description
user_id
string
unique identifier for the user making the authentication request
plugin_version_id
string
identifier for the version of the plugin being used for authentication
params
object, optional
[key: string]
Optional object containing additional parameters received in the redirection from the partner authentication. Concerning the Oauth2.0 protocol, the code is present within this array
Return
Resolves to an object containing the response status along the optional message.
Promise<ExternalSegmentAuthenticationResponse>
Parameter
Type
Description
status
enum['ok' | 'error' | 'not_implemented']
Status of the authentication process indicating success or failure
message
string, optional
optional message providing additional information about the authentication status
Code
Code example
onLogout
Handle the connector logout for either a user, or a datamart.
Input parameters
request (ExternalSegmentLogoutRequest): Request sent when logging out
Variable
Type
Description
user_id
string
Unique identifier for the user making the logout request
plugin_version_id
string
Identifier for the plugin version being used for the logout
datamart_id
string
Identifier for the datamart associated with the logout request
Return
Resolves to an object containing the response status along the optional message.
Promise<ExternalSegmentLogoutResponse>
Parameter
Type
Description
status
enum['ok' | 'error' | 'not_implemented']
Status of the authentication process indicating success or failure
message
string, optional
Optional message providing additional information about the authentication status
Code
Code example
Dynamic properties
onDynamicPropertyValuesQuery
Enable the feed creation form to dynamically suggest values from the partner solution, allowing users to select from these options. Additionally, one dynamic property may depend on another.
Input parameters
request (ExternalSegmentDynamicPropertyValuesQueryRequest): Request coming from the feed creation form.
Parameter
Type
Description
segment_id
string, optional
Optional identifier for the segment related to the feed being created
datamart_id
string
Identifier for the datamart associated with the feed being created
user_id
string
Unique identifier for the user making the query
properties
PluginProperty[], optional
Optional array of properties already set in the feed creation form
To better understand the properties array, here is an example type that can be found within it:
Parameter
Type
property_type
enum['STRING', 'URL', ...]
value
object[]
value (string, optional)
id (string, optional)
... depending on the property type
Return
Resolves to an object containing the array of the dynamic properties and their values to be displayed in the feed creation form.
// Trigger by the creation of a feed instance
protected async onExternalSegmentCreation(
_: ExternalSegmentCreationRequest,
ctx: InstanceContext,
): Promise<ExternalSegmentCreationPluginResponse> {
this.logger.debug(`${ctx.loggerPrefix} - onExternalSegmentCreation step`);
try {
if ( !hasIdentifyingResource(ctx) ) {
throw new Error(
`Your User Profiles do not contain enough information for Linkedin connector to rely on them alone. Either an ID (mobile id or hashed email) OR the couple first and last name are required. Please contact your account manager.`,
);
}
if (ctx.feedProperties.partnerSegmentId) {
return await knownPartnerSegmentIdWorkflow({
partnerSegmentId: ctx.feedProperties.partnerSegmentId,
ctx,
logger: this.logger,
});
}
return unknownPartnerSegmentIdWorkflow({ ctx, logger: this.logger });
} catch (err) {
this.logger.error(`${ctx.loggerPrefix} - onExternalSegmentCreation - something went wrong:`, err);
return {
status: 'error',
message: (err as Error).message,
visibility: 'PUBLIC',
};
}
}