Skip to main content

Two Integration Paths


Option A: Liquid Snippet (Online Store 2.0)

Step 1 — Add the snippet

Copy alana-predictive-search.liquid to your theme’s snippets/ directory via the Shopify Admin theme editor or CLI:

Step 2 — Configure API credentials

In Shopify Admin → Online Store → Themes → Customize → Theme Settings, add: Or set directly in config/settings_data.json:

Step 3 — Render the snippet

In your theme’s search template (e.g., sections/predictive-search.liquid or the search form partial), add:
The snippet automatically:
  1. Finds input[type="search"], input[name="q"], or #Search-In-Template
  2. Attaches autocomplete to the input
  3. Intercepts form submit to call Alana search
  4. Renders results in #alana-results-container

What the Liquid snippet provides

  • Autocomplete dropdown on keypress (200ms debounce)
  • Full search results grid on form submit
  • Spell correction suggestion with click-to-search
  • detail-page-view event on product card click
  • Persistent visitor ID via localStorage

Option B: Hydrogen Component (Headless)

Step 1 — Copy the component

Step 2 — Use in a route

Component props

Environment variable pattern

Store the API key in .env:
Then pass it to the component:

Security Notes

  • Use a search-only API key — never a service-role key
  • The Liquid snippet exposes window.AlanaShopify as a frozen object (Object.freeze) to prevent prototype pollution
  • All HTML from the Alana API (highlight snippets) is sanitized to <em> and <mark> tags only before rendering
Última modificação em 12 de março de 2026