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
1
const nudgeLayout = {
2
"dialogueId": "a6e66595-88e1-46d7-9dbb-947ad87a5973",
3
"webhook": "https://example.com/signup",
4
"sections": [
5
{
6
"title": "Want to stay up to date?",
7
"description": "Sign up for our newsletter and never miss our best offers!"
8
},
9
{
10
"form": {
11
"input": {
12
"label": "Email",
13
"type": "email",
14
"placeholder": "[email protected]",
15
"required": true
16
},
17
"button": {
18
"title": "Sign up"
19
}
20
}
21
}
22
]
23
}
Copied!

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
1
const nudgeLayout = {
2
"sections": [
3
{
4
"title": "Our best sale continues!",
5
"description": "50% on our most popular shoes.",
6
"buttons": [
7
{
8
"label": "View all",
9
"value": "http://example.com/sale"
10
}
11
]
12
},
13
{
14
"products": {
15
"title": "The most popular products:",
16
"items": [
17
{
18
"title": "Adidas",
19
"description": "Stan Smith - white",
20
"image": "http://lorempixel.com/200/200/shoes/",
21
"price": "699 ,-",
22
"productUrl": "http://example.com/stan-smith",
23
"linkUrl": "http://example.com/sale",
24
"linkText": "View all on sale"
25
}
26
]
27
}
28
}
29
]
30
}
Copied!

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
1
const nudgeLayout = {
2
"sections": [
3
{
4
"title": "Product feedback",
5
"description": "You seemed interested in our product! We would love to know you didn't want to try it."
6
},
7
{
8
"choices": {
9
"buttons": [
10
{
11
"text": "I love it",
12
"triggerDialogue": "a4bfc101-3a07-4c16-955d-9aa9575666c6"
13
},
14
{
15
"text": "I hate it",
16
"triggerDialogue": "a4bfc101-3a07-4c16-955d-9aa9575666c6"
17
},
18
{
19
"text": "I didn't understand",
20
"triggerDialogue": "a4bfc101-3a07-4c16-955d-9aa9575666c6"
21
},
22
{
23
"text": "Other",
24
"triggerDialogue": "a4bfc101-3a07-4c16-955d-9aa9575666c6"
25
}
26
]
27
}
28
}
29
]
30
}
Copied!

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.
1
const html = `
2
<style>
3
.nudge-text {
4
width: 50%;
5
}
6
7
p {
8
color: #333;
9
font-size: 14px;
10
}
11
</style>
12
<div class="nudge-wrapper">
13
<div class="nudge-text">
14
<p>Here you can display whatever contents you want.</p>
15
<p>Styling is also supported, and will be renderrerd!</p>
16
</div>
17
</div>
18
<script>
19
console.log("Even script tags are supported!");
20
</script>
21
`;
Copied!

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.
1
const html = (textContent) => `
2
<style>
3
.nudge-text {
4
width: 50%;
5
}
6
7
p {
8
color: #333;
9
font-size: 14px;
10
}
11
</style>
12
<div class="nudge-wrapper">
13
<div class="nudge-text">
14
<p>${textContent.slug}</p>
15
<p>${textContent.anotherSlug}</p>
16
</div>
17
</div>
18
`;
Copied!

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:
1
const html = `
2
<div>
3
<p>HTML contents</p>
4
</div>
5
`;
6
7
const nudgeLayout = {
8
sections: [
9
{
10
html,
11
},
12
],
13
};
14
15
window.kindlyChat.showNudge({ nudgeLayout });
Copied!
On the other hand, a completely custom solution use the following function:
1
const html = `
2
<div>
3
<p>HTML contents</p>
4
</div>
5
`;
6
7
const content = {
8
html,
9
onRendered: (element) => (element.style.height = "3000px"),
10
};
11
12
window.kindlyChat.showCustomNudge({ content });
Copied!

Functions and callbacks

For a comprehensive list of functioins and callbacks can be found here