Set Up the AI Agent on Specific Pages

Set Up the AI Agent on Specific Pages

Introduction

The AI Agent can be displayed only on the pages where you want customers to interact with it, allowing you to provide targeted assistance while keeping your storefront uncluttered. By configuring page-specific visibility, you can control exactly where the AI Agent appears, such as product pages, collection pages, or other selected pages. In this article, you'll learn how to configure the AI Agent to appear only on specific pages of your store.


Here are the steps to setup Ai Agent on specific pages:

Notes
Note: Ensure that you have already created the AI Agent bot. To learn how to create it, click here.
Step 1: Go to AI Agent >> My bots and click on the code icon.



Step 2: Click on the Copy code button.



Step 3: Go to Shopify admin >> Online store >> click on the 3 dots to open the menu >> Click on Edit code.



Step 4: Search for theme.liquid and click on Theme.liquid from the results.



Step 5: Copy the code below and paste it just above the closing </head> tag in your theme file.



Notes
Note:
  1. You need to replace 'your page LINK like /pages/aiagent' with your page link.
  2. Paste the AI Agent script for the bot that you want to display on the specific page below the text -  {% comment %} Paste the code below {% endcomment %}
  3. Paste the AI Agent script for the bot that you want to display on all pages below the else code text which is - {% comment %} Paste the else code below {% endcomment %}

  1. {% if request.path == 'your page LINK like /pages/aiagent' %}
     {% comment %} Paste the code below {% endcomment %}
      {% else %}
      {% comment %} Paste the else code below {% endcomment %}
    {% endif %}



Step 6: Click on the Save button.



The AI Agent will now be displayed on your storefront only on the pages that match the conditions you have configured.









Notes
Note: Similarly, if you have 3 bots, you can show the bots on a specific page by using an elsif condition.

{% if request.path == 'your page LINK like /pages/aiagent' %}
 {% comment %} Paste the code below {% endcomment %}
{% elsif request.path == 'your page LINK like /pages/aiagent2' %}
 {% comment %} Paste the code below {% endcomment %}
{% else %}
  {% comment %} Paste the else code below {% endcomment %}
{% endif %}