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.
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
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.
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.
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.
<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.
| Tool | What to check |
|---|---|
| GA4 | The Google tag loads in your root layout, once. |
| Meta, TikTok, Pinterest | Each pixel loads once, or our team adds its ID in Idukki. |
| Google Tag Manager | The container loads once. Gallery moments arrive as idukki_ugc. |
| Matomo or VWO | Route idukki_ugc through GTM, as for any store. |
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
- 01
Load the home page
The gallery shows. GA4 Realtime gets idukki_ugc_widget_view.
0 to 1 min
- 02
Go to a product page
Wait past 30 seconds first. The gallery should still mount.
1 to 2 min
- 03
Tap a tile
GA4 gets idukki_gallery_click. GTM Preview shows idukki_ugc with post_click.
2 to 4 min
- 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
- 1Tag Manager Help, History change trigger · Fires on URL fragment changes and the pushState API. Read 26 November 2026.
- 2Idukki help, Embed on Hydrogen, Next.js, Astro, Remix · Install snippets for each framework.
Continue reading
1 piece in this clusterThese long-form pieces on the Idukki blog link back to this article, go deeper on the cluster.
More from Rohin Aggarwal
- Rights and compliance
Cookie consent and UGC widgets: how to load pixels through your banner
The gallery does not read your cookie banner. Here is how to keep its GA4 and pixel events behind consent anyway.
- Measurement
How to track UGC and shoppable video in GA4, Meta, TikTok and Google Tag Manager
Which gallery and video events reach each tool. How adds stay counted once. How Matomo and VWO get them through GTM.
- Reviews and ratings
Headless product reviews via API: invite queue to widget
Run product reviews on a headless storefront. Invite queue, submit and media upload, PDP aggregates, mount options, auth and webhooks. We make Idukki.