Skip to main content

Triggering a pop-up Campaign greeting on a button click

Introduction

This tutorial will help you to create a button that will trigger a pop-up Campaigns greeting. The pop-up will be displayed only when the button is clicked. It requires a bit of JavaScript knowledge and the access to the LiveChat app.

The functional, live example can be found here: https://greeting-on-button-click.glitch.me/

How to set it?

Campaigns triggering conditions

First, open your LiveChat agent application and head to Engage > Campaigns or follow this link - https://my.livechatinc.com/engage/campaigns/recurring. There, click + New campaign to create a new one, or click on the name of one of the existing ones on the list.

Once your Campaing look is customized, proceed to the triggering conditons by clicking the Next: set conditions button at the bottom of the page.

There, you can set the "Custom variable" type condition that is matched only if the trigger_campaign variable on your website receives the yes value. Depending on your use case, you can choose a different variable name and value to trigger the Campaign when some different event takes place on your website.

Campaigns setup

Once it is set, click Save campaign at the bottom of the page.

Custom button code

The abovementioned trigger_campaign variable value can be set to yes in many ways. In our example we will create a custom button that executes that action on our page. Its code is:

    <script>
function triggerCampaign() {
LiveChatWidget.call("set_session_variables", {
trigger_campaign: "yes",
});
}
</script>

<button onclick="triggerCampaign()">
Click me to trigger the Campaign pop-up!
</button>

The first part of the above code defines the variable value setting function. The second one is our custom buttom executing it once clicked. You can test it with our live example here - https://greeting-on-button-click.glitch.me/. Remember, that it works only once per visitor browsing session so you need to open a new, fresh browsing tab (for example Chrome Guest Mode) to trigger it once again.

If you have any questions, let us know!

Yours, Text Team 💛