You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 23, 2024. It is now read-only.
console.log("Message received from campaign with key:", data.campaignKey);
286
+
});
287
+
}
288
+
};
289
+
```
290
+
291
+
Called when the embed script has been loaded, and before it is initialized. This is useful for subscribing to events (see `subscribeEvent`) - subscribing here ensures subscriptions are in place before events are triggered.
292
+
279
293
#### parentElement
280
294
281
295
```html
@@ -433,6 +447,64 @@ Used to initialize Embed2 on your page. This action is triggered by default inte
if (eventKey === "ada:campaigns:message_received") {
464
+
console.log("Message received from campaign with key:" data.campaignKey);
465
+
}
466
+
467
+
if (eventKey === "ada:campaigns:opened") {
468
+
console.log("Chat opened after being shown campaign with key:" data.campaignKey);
469
+
}
470
+
471
+
if (eventKey === "ada:campaigns:message_received") {
472
+
console.log("Message received from campaign with key:" data.campaignKey);
473
+
}
474
+
});
475
+
```
476
+
477
+
When certain events happen in Ada, events will be triggered. Each event consists of an event key and a data payload. Using `subscribeEvent`, you can define callbacks that get called when a specific event is triggered.
478
+
479
+
Callbacks will be triggered whenever an event _starts with_ the `eventKey` provided to `subscribeEvent`. This allows subscribing to all events of a certain category - for example, the callback in a subscription to `ada:campaigns` will be called on `ada:campaigns:message_received`, `ada:campaigns:opened`, and any other events beginning with `ada:campaigns`.
480
+
481
+
Two arguments will be provided to each callback when it is called: `data` and `context`. `data` is specific to each event (see table below). `context` is an object with a single property `eventKey`, which is the event key of the event that triggered the callback to be called.
482
+
483
+
`subscribeEvent` returns a number `subscriptionId` which can be used to unsubscribe later (see `unsubscribeEvent` below).
484
+
485
+
It is strongly recommended that initial subscriptions to events be placed in the `onAdaEmbedLoad` function. This ensures that the embed script has been loaded (so it is available to accept subscriptions), and that subscriptions happen before any events are triggered so that no events are missed.
486
+
487
+
The following is a list of the currently available events that can be subscribed to. More events may be added in the future.
488
+
489
+
Event key | Data | Description
490
+
-------------- | -------------- | --------------
491
+
`ada:campaigns:message_received` | `campaignKey` - the key of the campaign which triggered the received message | Triggered when the chat application receives a message that originates from a campaign.
492
+
`ada:campaigns:opened` | `campaignKey` - the key of the last campaign shown before chat was opened | Triggered when chat is opened after a proactive campaign has been shown.
493
+
`ada:campaigns:engaged` | `campaignKey` - the key of the last campaign shown before the conversation was engaged | Triggered when the chatter engages a conversation (sends a message) after being shown a campaign in the same session.
console.log("Message received from campaign with key:", data.campaignKey);
501
+
});
502
+
503
+
window.adaEmbed.unsubscribeEvent(subscriptionId);
504
+
```
505
+
506
+
This function can be used to remove subscriptions created with the `subscribeEvent` function above. It takes a single parameter `subscriptionId`, which is the id of the subscription to be removed.
0 commit comments