Call the API whilst page is loading
Event handler
Use our JavaScript API to respond to events that happen before our script has loaded with a new event handler, ready:function(api){}
, in the continuallySettings object.
<script>var continuallySettings = {appID: "xyz123456", ready: function(continually){/*your code here*/}}</script><br>
The code you pass to the ready
event handler fires once Continually is available for users to interact with.
Read more about how the ready event works.
Example: catching button clicks when the embed script has not been executed
In this example, if you are using your own button by assigning a continually
class, we won't be aware of any clicks on that button before our script has loaded and executed.
<script>var continuallySettings = {appID: "xyz123456", delay: 3000, ready: function(continually){/*your code here*/}}</script>
This might happen because of how the browser loads the page, or in a scenario where you are delaying the loading of the Continually script with the delay
parameter.
Here, you can define a callback that will catch clicks to your custom button with some additional JavaScript.
To do that, we'll create a new variable clickStartConversation
that is set to true when you click the button.
Add this code to the head section of your document along with the embed code:
<script> var clickStartConversation = false; var continuallySettings = {appID: "xyz123456", ready: function(continually){ if (clickStartConversation) {api.startConversation();}}}; </script><br>
And in the body:
<a role="button" class="continually" onclick="clickStartConversation = true;">Start conversation</a><br>