Skip to content
NewProduct Q&A: shoppers ask on your product page and get your answers.See how it works
IdukkiIdukki
Embedding

How to track UGC galleries on Hydrogen, Next.js and other headless stores

Mount galleries after each route change. Keep their events flowing to GA4, the pixels and GTM. Then check it in the browser.

The gallery shows on the home page. A shopper taps through to a product page, and the gallery space is empty. GA4 shows views from the first page and nothing after. The site is a single-page app, and nothing told the gallery the page changed.

In this article

This guide gets every product page its gallery, and every gallery its events. It takes one helper function and one component.

Why the gallery goes missing

The loader runs once, on the first page. It mounts every gallery it finds. Then it watches the page for 30 seconds and mounts any that appear.

A shopper who opens a product page two minutes later gets no gallery. The container is in the page, but nothing is watching any more. No gallery means no events either.

CompareTwo ways to fix it
1Code

Idukki.mount() in a component

Mount on render, unmount on leave.

Wins at

  • Exact: runs when the element exists
  • Cleans up timers and listeners on unmount

Struggles with

  • Needs a developer for each framework
2No code

data-idk-spa="1" on the loader

The widget watches route changes itself.

Wins at

  • Works from a tag manager
  • Mounts after pushState, replaceState and popstate

Struggles with

  • Does not unmount galleries on routes you leave

Pick the component call when you own the code. Pick the attribute when the snippet goes in through a tag manager.

Mount from the component

Add the loader once, in the document head. Then use this helper. It works before and after the loader runs, so load order does not matter.

js
function idukki(command, target) {
  var api = (window.Idukki = window.Idukki || { q: [] });
  api.q.push([command, target]);
}

On Hydrogen or any React store, call it from an effect. The gallery mounts when the element exists and unmounts when it leaves.

tsx
import { useEffect, useRef } from 'react';

function idukki(command: 'mount' | 'unmount', target: Element) {
  const w = window as any;
  (w.Idukki = w.Idukki || { q: [] }).q.push([command, target]);
}

export function IdukkiGallery({ bguid, guid, productId }: { bguid: string; guid: string; productId?: string }) {
  const ref = useRef<HTMLDivElement>(null);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    idukki('mount', el);
    return () => idukki('unmount', el);
  }, [guid]);
  return <div ref={ref} data-ugc="idukki" data-bguid={bguid} data-guid={guid} filter-pid={productId} />;
}

Mounting twice does nothing, so a re-render is safe. A change of filter-pid refetches on its own, so a variant switch needs no remount.

On Next.js, load the loader with next/script in the root layout. The gallery component is a client component with the same effect.

Or let the widget watch the routes

If the snippet goes in through a tag manager, you may not own the components. Add one attribute to the loader tag instead.

html
<script src="https://assets.idukki.io/version/script_0" data-idk-spa="1" defer></script>

The widget then mounts new galleries after each change of path or query. Hash changes are ignored. It never unmounts, so long sessions should use the component call.

Getting the events into your tools

Once a gallery mounts, it sends events like a gallery on any theme. Your tags only need to be on the page.

ToolWhat to check
GA4The Google tag loads in your root layout, once.
Meta, TikTok, PinterestEach pixel loads once, or our team adds its ID in Idukki.
Google Tag ManagerThe container loads once. Gallery moments arrive as idukki_ugc.
Matomo or VWORoute idukki_ugc through GTM, as for any store.
What a headless store needs for each tool.

Your own page views on route changes are a separate job. In GTM, a History Change trigger fires on pushState. The gallery’s events do not depend on it.

The event list is in the widget event reference. The GTM setup is in one GTM trigger for every widget moment.

Check it in five minutes

A quick test on a preview build

  1. 01

    Load the home page

    The gallery shows. GA4 Realtime gets idukki_ugc_widget_view.

    0 to 1 min

  2. 02

    Go to a product page

    Wait past 30 seconds first. The gallery should still mount.

    1 to 2 min

  3. 03

    Tap a tile

    GA4 gets idukki_gallery_click. GTM Preview shows idukki_ugc with post_click.

    2 to 4 min

  4. 04

    Go back

    The home page gallery mounts again. Mounting twice does nothing.

    4 to 5 min

FAQs

  • Do I need to unmount galleries?

    Yes, when a route that held one is destroyed. Unmount stops its timers and listeners.

  • Will SSR break the gallery?

    No. Call mount only in the browser, from an effect. The container renders on the server as plain markup.

  • Can I render tiles on the server?

    Yes. Read the gallery’s public JSON payload. See /platforms/custom-headless for the snippet and the payload.

Sources

  1. 1Tag Manager Help, History change trigger · Fires on URL fragment changes and the pushState API. Read 26 November 2026.
  2. 2Idukki help, Embed on Hydrogen, Next.js, Astro, Remix · Install snippets for each framework.
#headless#hydrogen#nextjs#ga4#google-tag-manager#single-page-app

Continue reading

1 piece in this cluster

These long-form pieces on the Idukki blog link back to this article, go deeper on the cluster.

More from Rohin Aggarwal