APIs

Nudge API

in addition to the nudge editor in our platform, nudges also comes with a powerful api that let's you create, control and make use of various events the nudge api can also be used in addition to nudges created with the platform, to easier maintain the text fields used nudge types there's various types of nudges to make use of, based on your needs each type comes with its own properties and functionality, but all share a set of the same values values needs to be wrapped in a sections array, to split up object throughout the nudge as well see each nudge type below for example recipes nudges created with the editor each have a identifying slug string, which is used when calling the nudge from the api form nudge a form nudge is a great way to handle subscriptions on your website without being too intrusive, for example a newsletter signup, or to download an e book it comes with a call to action in form of an input and a button when the form is submitted it can call a webhook, and trigger a specific dialogue of your choice example recipe { &#x9;"dialogueid" "a6e66595 88e1 46d7 9dbb 947ad87a5973", &#x9;"webhook" "https //example com/signup", &#x9;"sections" \[ &#x9; { &#x9; "title" "want to stay up to date?", &#x9; "description" "sign up for our newsletter and never miss our best offers!" &#x9; }, &#x9; { &#x9; "form" { &#x9; "input" { &#x9; "label" "email", &#x9; "type" "email", &#x9; "placeholder" "test\@example com", &#x9; "required" true &#x9; }, &#x9; "button" { &#x9; "title" "sign up" &#x9; } &#x9; } &#x9; } &#x9;] } product nudge with the product nudge you can showcase a hand picked selection of products, and is great for promoting either current offers or best sellers similar to the form nudge it also comes with a call to action, but in the form of a button each product is represented with a image, title, description, price and call to action in the example below, we use multiple sections to divide up our nudge content example recipe { &#x9;"sections" \[ &#x9; { &#x9; "title" "our best sale continues!", &#x9; "description" "50% on our most popular shoes ", &#x9; "buttons" \[ &#x9; { &#x9; "label" "view all", &#x9; "value" "http //example com/sale" &#x9; } &#x9; ] &#x9; }, &#x9; { &#x9; "products" { &#x9; "title" "the most popular products ", &#x9; "items" \[ &#x9; { &#x9; "title" "adidas", &#x9; "description" "stan smith white", &#x9; "image" "http //lorempixel com/200/200/shoes/", &#x9; "price" "699, ", &#x9; "producturl" "http //example com/stan smith", &#x9; "linkurl" "http //example com/sale", &#x9; "linktext" "view all on sale" &#x9; } &#x9; ] &#x9; } &#x9; } &#x9;] } multiple choice multiple choice nudge is a great way to collect feedback on various aspect of your website it supports an array of buttons, which each has an attached dialogue it will trigger when pressed in the example below, we use multiple sections to divide up our nudge content example recipe { &#x9;"sections" \[ &#x9; { &#x9; "title" "product feedback", &#x9; "description" "you seemed interested in our product! we would love to know you didn't want to try it " &#x9; }, &#x9; { &#x9; "choices" { &#x9; "buttons" \[ &#x9; { &#x9; "text" "i love it", &#x9; "triggerdialogue" "a4bfc101 3a07 4c16 955d 9aa9575666c6" &#x9; }, &#x9; { &#x9; "text" "i hate it", &#x9; "triggerdialogue" "a4bfc101 3a07 4c16 955d 9aa9575666c6" &#x9; }, &#x9; { &#x9; "text" "i didn't understand", &#x9; "triggerdialogue" "a4bfc101 3a07 4c16 955d 9aa9575666c6" &#x9; }, &#x9; { &#x9; "text" "other", &#x9; "triggerdialogue" "a4bfc101 3a07 4c16 955d 9aa9575666c6" &#x9; } &#x9; ] &#x9; } &#x9; } &#x9;] } combining nudge from editor and api when using the api to trigger a nudge, it's possible to pass both a nudgelayout object, and a slug string when this is done, both nudges will be combined into one this can be useful if you have nudge created using the api, but need to easily maintain texts from the platform custom nudge the custom nudge is a more powerful nudge type, which let's you completely customize the contents of the nudge it accepts either a string or a function, which can contain some html code custom nudges supports its own trigger function, depending on whether or not you want our template to wrapp your nudge or build your own html as string if you want the nudge to be completely custom, it's fine to send in the html as a string see example below const html = ` \<style> nudge text { width 50%; } p { color #333; font size 14px; } \</style> \<div class="nudge wrapper"> \<div class="nudge text"> \<p>here you can display whatever contents you want \</p> \<p>styling is also supported, and will be renderrerd!\</p> \</div> \</div> \<script> console log("even script tags are supported!"); \</script> `; html as function html can be passed as a function to make use of text content from the platform this is useful if you have a custom nudge solution, but need to easily maintain its texts simply create a custom nudge from the editor, and call the text blocks slug to display it const html = (textcontent) => ` \<style> nudge text { width 50%; } p { color #333; font size 14px; } \</style> \<div class="nudge wrapper"> \<div class="nudge text"> \<p>${textcontent slug}\</p> \<p>${textcontent anotherslug}\</p> \</div> \</div> `; triggering a custom nudge triggering a custom nudge is slightly different than the other nudge types, as it uses html content you can choose between using our nudge template, or create your own from scratch the template includes our nudge element with built in styling and responsiveness using our nudge template, the content sent as it can be triggering like this const html = ` \<div> \<p>html contents\</p> \</div> `; const nudgelayout = { &#x9;sections \[ &#x9; { &#x9; html, &#x9; }, &#x9;], }; window\ kindlychat shownudge({ nudgelayout }); on the other hand, a completely custom solution use the following function const content = ` \<div> \<p>html contents\</p> \</div> `; const onrendered (element) => (element style height = "3000px"); window\ kindlychat showcustomnudge({ content, onrendered }); functions and callbacks for a comprehensive list of functions and callbacks can be found here https //docs v2 kindly ai/chat api#qc callback reference deprecated