{"versionId":"d8b8bee7-eeb0-4b10-a5c7-08dce67f4e26","articleId":"4b167fc0-98a8-438c-4c4f-08db14571314","title":"Build interactions between your site and your bot","tags":["engagements","integrations","All articles"],"content":"<div class=\"mce-toc\">\n<h2>Table of Contents</h2>\n<ul>\n<li><a href=\"#mcetoc_1gqpt423v3o\">What can Helpfruit buttons/links be used for?</a></li>\n<li><a href=\"#mcetoc_1gqpt423v3p\">How to add Helpfruit buttons/links to your site</a>\n<ul>\n<li><a href=\"#mcetoc_1gj0mace313j\">Add a button that opens the&nbsp;chatbot and asks it a question</a></li>\n<li><a href=\"#mcetoc_1gj0mace313j\">Add a button that opens the&nbsp;chatbot and initiates an engagement</a></li>\n</ul>\n</li>\n<li><a href=\"#mcetoc_1ia6p1c071c\">Using URLs to interact with the chatbot</a>\n<ul>\n<li><a href=\"#mcetoc_1ia6q0dg4be\">Step one: Create the URL</a></li>\n<li><a href=\"#mcetoc_1ia6q0dg4bf\">Step two: Add the script to your page</a></li>\n</ul>\n</li>\n</ul>\n</div>\n<p>Add buttons or links to your web page that open your chatbot&nbsp;and ask a question or send an event.</p>\n<p>This can help direct support traffic to your chatbot, and means customers don&rsquo;t need to type at all and get their answer more quickly - without leaving the page. How good!</p>\n<h2 id=\"mcetoc_1gqpt423v3o\">What can Helpfruit buttons/links be used for?</h2>\n<ul>\n<li>Provide contextual help right there on the page</li>\n<li>Intercept common questions that come through to your support team - have your chatbot answer them, immediately and in situ</li>\n<li>Use <a href=\"https://www.faqbot.ai/features/forms\">a</a><a href=\"https://help.faqbot.ai/article/forms\" target=\"_blank\" rel=\"noopener\"> conversational form experience</a> to capture leads</li>\n<li>Add a special button to product pages that ask your chatbot &ldquo;how much does shipping cost?&rdquo;</li>\n<li>Engage prospects in chat around a potential sale, eg a &ldquo;Talk to us&rdquo; button starts live chat</li>\n</ul>\n<p>&nbsp;</p>\n<p><img src=\"https://portal.faqbot.nz/api/images/079d861d72cc4aca80c65588df217079/files/page-to-bot.png?width=1000&amp;height=\"></p>\n<h2 id=\"mcetoc_1gqpt423v3p\">How to add Helpfruit buttons/links to your site</h2>\n<p>Creating buttons is easy, although you will need some basic HTML and JavaScript knowledge.</p>\n<ul>\n<li>First, make sure the Helpfruit chatbot&nbsp;is loaded on your site (see <a href=\"https://help.faqbot.ai/article/website-integration\" target=\"_blank\" rel=\"noopener\">website integration</a>).</li>\n<li>Then add the relevant code snippet just above the &lt;/body&gt; tag.</li>\n</ul>\n<h3 id=\"mcetoc_1gj0mace313j\">Add a button that opens the&nbsp;chatbot and asks it a question</h3>\n<p><strong>1. Use this version if you are already using&nbsp;JQuery on your site:</strong></p>\n<p><code>&lt;script&gt;</code><br><code>$(\".faqbot-btn\").click(function() {</code><br><code>&nbsp; var question = $(this).attr(\"data-question\");</code><br><code>&nbsp; window.faqbot.open();</code><br><code>&nbsp; window.faqbot.askQuestion(question)</code><br><code>})</code><br><code>&lt;/script&gt;</code></p>\n<p><strong>2. If you prefer to use vanilla JS use the following code:</strong></p>\n<p><code>&nbsp;&lt;script&gt;</code><br><code>function askQuestion(event) {</code><br><code>var question = event.target.getAttribute(\"data-question\");</code><br><code>&nbsp;if (window.faqbot) {</code><br><code>&nbsp; &nbsp;window.faqbot.open();</code><br><code>&nbsp; &nbsp;window.faqbot.askQuestion(question);</code><br><code>&nbsp;}</code><br><code>}</code><br><code>document.addEventListener('click',function (event) {</code><br><code>&nbsp; if (event.target.closest('.faqbot-btn')) {</code><br><code>&nbsp; &nbsp; askQuestion(event);</code><br><code>&nbsp; }</code><br><code>})</code><br><code>&lt;/script&gt;</code></p>\n<p><strong>3. Create your question button or link</strong></p>\n<p>To create a button (or a link) that asks a question, add the &ldquo;faqbot-btn&rdquo; custom CSS class to them and a custom attribute &ldquo;data-question&rdquo; together with the question text you want to ask,&nbsp;eg:</p>\n<p><code>&lt;a data-question=\"this is my question\" href=\"#\" class=\"faqbot-btn\"&gt;&lt;div&gt;Ask a question&lt;/div&gt;&lt;/a&gt;</code></p>\n<p>The code above (step 1/2) will look for these buttons/links on the page, and will open your&nbsp;chatbot&nbsp;and pass the question through when the button is clicked.</p>\n<p>&nbsp;</p>\n<h3 id=\"mcetoc_1gj0mace313j\">Add a button that opens the&nbsp;chatbot and initiates an engagement</h3>\n<p>The code snippets are very similar if you want to trigger an engagement from a button (or link) on your site.</p>\n<p><strong>1. Use this version if you are already using JQuery on your site:</strong></p>\n<p><code>&lt;script&gt;</code><br><code>$(\".faqbot-btn\").click(function() {</code><br><code>&nbsp; var eventName&nbsp;= $(this).attr(\"data-event-name\");</code><br><code>&nbsp; window.faqbot.open();</code><br><code>&nbsp; window.faqbot.triggerEngagementEvent(eventName);</code><br><code>})</code><br><code>&lt;/script&gt;</code></p>\n<p><strong>2. If you prefer to use vanilla JS use the following code:</strong></p>\n<p><code>&lt;script&gt;</code><br><code>function triggerEngagementEvent(event) {</code><br><code>&nbsp;var eventName&nbsp;= event.target.getAttribute(\"data-event-name\");</code><br><code>&nbsp;if (window.faqbot) {</code><br><code>&nbsp; &nbsp;window.faqbot.open();</code><br><code>&nbsp; &nbsp;window.faqbot.triggerEngagementEvent(eventName);</code><br><code>&nbsp;}</code><br><code>}</code><br><code>document.addEventListener('click',function (event) {</code><br><code>&nbsp; if (event.target.closest('.faqbot-btn')) {</code><br><code>&nbsp; &nbsp; triggerEngagementEvent(event);</code><br><code>&nbsp; }</code><br><code>})</code><br><code>&lt;/script&gt;</code></p>\n<p><strong>3. Create your engagement button or link</strong></p>\n<p>To create a button (or a link) that triggers an engagement, add the &ldquo;faqbot-btn&rdquo; custom CSS class to them and a custom attribute &ldquo;data-event-name&rdquo; together with the button text you want to show the user, eg:</p>\n<p><code>&lt;a data-event-name=\"myEventName\" href=\"#\" class=\"faqbot-btn\"&gt;&lt;div&gt;Button text&lt;/div&gt;&lt;/a&gt;</code></p>\n<p>The code above will look for these buttons/links on the page and will open FAQ Bot and pass the engagement through when the button is clicked.</p>\n<h2 id=\"mcetoc_1ia6p1c071c\">Using URLs to interact with the chatbot</h2>\n<p>It's also possible to provide a link to your website - eg in a newsletter or displayed QR code - that will then open your&nbsp;chatbot. It could even ask a question of the chatbot&nbsp;or trigger an engagement - all from that one link.</p>\n<p>To achieve this you need to add a script to your webpage - either via a tool like google tag manager or directly with your web development team.</p>\n<h3 id=\"mcetoc_1ia6q0dg4be\">Step one: Create the URL</h3>\n<p>First, you need to create a URL that provides enough information that the script can then achieve your goals, eg&nbsp;<a href=\"https://mysite.com?hf-open=1&amp;hf-question=who%20are%20you\" aria-invalid=\"true\">https://mysite.com?hf-open=1&amp;hf-question=who%20are%20you</a></p>\n<p>The part after the \"?\" is called the query parameter part. It contains a series of key value pairs, each separated by an \"&amp;\" character.&nbsp; In example above we have:</p>\n<ul>\n<li>hf-open=1</li>\n<li>hf-question=<a href=\"https://mysite.com?hf-open=1&amp;hf-question=who%20are%20you\" aria-invalid=\"true\">who%20are%20you</a></li>\n</ul>\n<p>The \"%20\" characters in the hf-question parameter are used to replace spaces in the question. \"%20\" is an example of URL encoding - required as URLs cannot contain spaces (and some other special characters).&nbsp; Your browser will automatically replace these characters with the correct character when it is time to use them.</p>\n<h3 id=\"mcetoc_1ia6q0dg4bf\">Step two: Add the script to your page</h3>\n<p>Secondly, you need to add a script to your page that can retrieve these parameter values and then take action:</p>\n<pre class=\"language-javascript\"><code>(function () {\n    var hf = window.faqbot;\n\n    function getQueryParams() {\n        var params = {};\n        var queryString = window.location.search;\n        var urlParams = new URLSearchParams(queryString);\n    \n        // Loop through all parameters and add to params object\n        urlParams.forEach(function (value, key) {\n            params[key] = value;\n        });\n    \n        return params;\n    }\n\n    function onFaqBotReady() {\n        window.removeEventListener(\"faqbotready\", onFaqBotReady);\n        return hf &amp;&amp; hf.open();\n    }\n\n    function openFaqBot() {\n        if (hf &amp;&amp; hf.open) {\n            hf.open();\n        } else {\n            window.addEventListener(\"faqbotready\", onFaqBotReady);\n        }\n    }\n    \n    // Check if 'hf-open' parameter exists and its value is '1'\n    var queryParams = getQueryParams();\n    if (queryParams[\"hf-open\"] === \"1\") {\n        openFaqBot();\n    }\n\n    // Check if 'hf-question' parameter exists and its value is not empty\n    // If so, ask the question when ready\n    function onFaqBotReadyAskQuestion() {\n        var question = queryParams[\"hf-question\"];\n        var hf = hf;\n        hf.askQuestion(question);\n        window.removeEventListener(\"faqbotready\", onFaqBotReadyAskQuestion);\n    }\n\n    function askQuestion(question) {\n        if (hf &amp;&amp; hf.askQuestion) {\n            hf.askQuestion(question);\n        } else {\n            window.addEventListener(\"faqbotready\", onFaqBotReadyAskQuestion);\n        }\n    }\n\n    var question = queryParams[\"hf-question\"] || \"\";\n    if (question !== \"\") {\n        askQuestion(question);\n    }\n})();</code></pre>\n<p>Loading this script on a page will look for query parameters \"hf-open\" and/or \"hf-question\". If detected, the script will open the bot and ask a question respectively. <br><br></p>","description":"","isMarkdown":false,"publishedOnUtc":"2024-10-15T00:43:38.6882479","modifiedOnUtc":"2023-03-05T22:10:54.1092679"}