Hi everyone,
I’m trying to either get the page path or the URL parameters for a custom event, but I can’t find anything in the web pixels API documentation. Is there any way to access that information with a custom web pixel script?
Thanks in advance!
PieLab
November 21, 2025, 9:32am
2
Hey pal @hdewendt !
You cannot use window.location because the sandbox blocks it.
Instead, you must access the URL through the event object’s context.
You can use event.context.document.location.href and parse it with the standard URL API:
analytics.subscribe('your_custom_event', (event) => {
// 1. Get the full URL from the safe context
const rawUrl = event.context.document.location.href;
const urlObj = new URL(rawUrl);
// 2. Get the Path (e.g., "/products/shirt")
const path = urlObj.pathname;
// 3. Get Parameters (e.g., "123" from ?variant=123)
const myParam = urlObj.searchParams.get('variant');
console.log(`Path: ${path}, Param: ${myParam}`);
});
Hope this helps!
1 Like
That worked, thank you so much!