Adapt the start of your bot to your advertising campaign or your newsletter
Do you want to be able to redirect your users to your website while starting the bot on a sequence dedicated to your advertising campaign or your newsletter to personalize the experience of your users? Follow the guide!
1. Prerequisites
If the expression “embedded code” does not speak to you, or if you have not yet proceeded to a first installation of this embedded code, we strongly invite you to read the article dedicated to the installation of the chatbot .
Now you can open your favorite notepad and paste the code dedicated to the installation. Sample code:
<script type="text/javascript">
window.chatboxSettings = {
appKey: <YOUR_APP_KEY>,
websiteId: <YOUR_WEBSITE_ID>,
language: 'fr'
};
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = 'https://cbassets.botnation.ai/js/widget.js';
js.async = true;
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'chatbox-jssdk'));
</script>
2. Adaptation of the installation code
We are going to edit the code to be embedded as follow so that we can redirect to a sequence corresponding to a BLOCK_ID thanks to a web address of the form https://example.com?ref=blockid:<BLOCK_ID>:
- Copy the following code:
var refMatch = window.location.href.match(/ref=(blockid:[a-z0-9]{24}|restart)/);
if (refMatch) window.chatboxSettings['ref'] = refMatch[1];
- Paste it into your installation code as follows:
<script type="text/javascript">
window.chatboxSettings = {
appKey: <YOUR_APP_ID>,
websiteId: <YOUR_WEBSITE_ID>,
language: 'fr'
};
var refMatch = window.location.href.match(/ref=(blockid:[a-z0-9]{24}|restart)/);
if (refMatch) window.chatboxSettings['ref'] = refMatch[1];
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement(s);
js.id = id;
js.src = 'https://cbassets.botnation.ai/js/widget.js';
js.async = true;
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'chatbox-jssdk'));
</script>
3. Building the web address of your site to a particular sequence of the bot
We have seen that to start the bot on a particular sequence we could do it via a url of the type https://example.com?ref=blockid:<BLOCK_ID>. Of course “example.com” should be replaced by your site address, but what about the <BLOCK_ID>? Here’s how to do it:
- On the sequence to be activated, go to the title bar
- hovering over the cogwheel displays the parameters of the sequence, including the block id to be copied and pasted
So I get the url : https://example.com?ref=blockid:5eb1710f956482f5a9747d2