Methods you can use in the Continually object
There are several methods available in JS API:
- on(event, callback)
- startConversation(botID, appID)
- identity(identityData)
- init()
- destroy()
- restart()
on(event, callback)
Listen for an event triggered by continually object. Please refer to events section for more information.
Parameters:
event
- event name
callback
- a JS function that will be executed if an event is fired. Event data structure will be provided as the first parameter.
Usage:
/* Inside continuallySettings object */ <script> var continuallySettings = { appID: "xyz123456", ready: function(continually){ continually.on('emailCapture', function (data){ console.log(data.lead.email); }); } }; </script> /* Outside of continuallySetting object (please note that continually embed script should be loaded before making this call, so this method can't be mixed with defer / async attributes) */ <script>var continuallySettings = {appID: "xyz123456"};</script> <script src="https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js"></script> /*........*/ <script> continually.on('ready', function (continually){ continually.on('emailCapture', function (data){ console.log(data.lead.email); }); }); </script>
startConversation(botID, appID)
Open sidebar with current conversation (or override conversation ID that is loaded automatically by targeting rules).
Parameters:
botID
- if specified, it loads a bot identified by botID
, for the appID
defined in continuallySettings
object
appID
- if specified, it loads a bot identified by botID
, for the appID
Possible options are:
continually.startConversation(); // Open sidebar and load a bot according to targeting rules
continually.startConversation(botID); // Open sidebar and load a bot specified by the parameter
botID
continually.startConversation(botID, appID); // Open sidebar and load a bot specified by botID that belongs to another company specified by appID
Usage:
/* Inside continuallySettings object */ <script> var continuallySettings = { appID: "xyz123456", ready: function(continually){ continually.startConversation(); // open sidebar and load bot by targeting rules // continually.startConversation('yyyyy'); // override current bot with bot with ID yyyyy // continually.startConversation('aaaaa','bbbbb'); // load bot id aaaaa that belongs to team bbbbb } }; </script> /* You can also use it separately (please note that continually embed script should be loaded before making this call, so this method can't be used with defer / async attributes) */ <script>var continuallySettings = {appID: "xyz123456"};</script> <script src="https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js"></script> /*........*/ <script> continually.on('ready', function(continually){ continually.startConversation(); // open sidebar and load bot by targeting rules // continually.startConversation('yyyyy'); // override current bot with bot with ID yyyyy // continually.startConversation('aaaaa','bbbbb'); // load bot id aaaaa that belongs to team bbbbb }); </script>
identity(identityData)
Update lead information in Continually, please also refer to Identify your users for more information.
Parameters:
identityData
- a JS object that contains information about a lead. The attributes name
, email
, company
, phone
are natively supported and will be available for use in the conversation.
You can also provide data for custom attributes. To do this, you must specify the user's email
attribute together with any other attributes you want. email
is a mandatory attribute and can't be omitted.
To use custom attributes specified in identityData
in the conversation flow, you should create a custom field with the same name in the bot builder.
If no custom field exists, the data you pass will not be available in the conversation flow.
All attribute data passed to Continually will be shown on the lead overview page.
For example, if a bot has a custom field named @age and identityData
contains an attribute age
:
<code>{email: "test@example.com", age: 29}
The value 29
will be used in conversation flow as the value for the custom field @age.
Validation rules
We validate the data you send to Continually through identityData
against these rules:
name
should be string between 2 - 191 characters long, optionalcompany
should be string between 2 - 191 characters long, optionalphone
should be string between 7 - 191 characters long, optionalemail
is required and should be a valid email- the name of any custom attribute must be no longer than 191 characters. The value of the parameter should be no longer than 500 characters.
Usage:
/* Inside continuallySettings object */ <script> var continuallySettings = { appID: "xyz123456", ready: function(continually){ continually.identity({ name: "John Smith", email: "test@example.com", phone: "+123456789", company: "ACME", age: 31, language: "English" }); } }; </script> /* You can also use it separately (please note that continually embed script should be loaded before making this call, so this method can't be used with defer / async attributes) */ <script>var continuallySettings = {appID: "xyz123456"};</script> <script src="https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js"></script> /*........*/ <script> continually.on('ready', function(continually){ continually.identity({ name: "John Smith", email: "test@example.com", phone: "+123456789", company: "ACME", age: 31, language: "English" }); }); </script>
init()
This method should be used to initialize the Continually object after calling continually.destroy()
You can use the init()
and destroy()
as a pair to reload the Continually widget if you change the HTML structure of the web page using JavaScript.
The event listeners defined in the on('ready', callback)
method will be called again during initialization.
<script>var continuallySettings = {appID: "xyz123456"};</script> <script src="https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js"></script> <script> continually.destroy(); // remove DOM elements, timers, event listeners and so on /* Manipulating DOM elements */ continually.init(); // set up Continually object again </script>
destroy()
Gracefully unloads the Continually object and removes all DOM elements associated with it. If you need to change <body>, you must call this method beforehand.
<script>var continuallySettings = {appID: "xyz123456"};</script> <script src="https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js"></script> <script> continually.destroy(); // remove DOM elements, timers, event listeners and so on /* Manipulating DOM elements */ continually.init(); // set up Continually object again </script>
restart()
Reload Continually object. It calls destroy()
and init()
internally
<script>var continuallySettings = {appID: "xyz123456"};</script> <script src="https://cdn-app.continual.ly/js/embed/continually-embed.latest.min.js"></script> <script> window.history.pushState('', 'Test', '/test'); continually.restart(); // Reload Continually, in this example, another bot can be loaded according // to targeting rules for /test url. </script>