A developer is trying to access logged-in user data (email, customer ID) from Shopify’s web pixel analytics events, but the event payload arrives empty.
Proposed Solution:
Another user suggests embedding customer data directly in the storefront using Liquid templates. This involves adding a JavaScript snippet to theme files that exposes customer information via a global variable (window.loggedInCustomer), which the pixel script can then read.
Key Limitation Identified:
While this Liquid-based approach works, it requires manual theme code modifications for each store. For a pixel intended to work across multiple stores, this creates a scalability problem—non-technical store admins would need to edit theme files, which is complex and risks breaking the storefront.
Current Status:
The discussion remains open with no universal solution identified for accessing user data across all stores without manual theme customization.
Summarized with AI on October 27.
AI used: claude-sonnet-4-5-20250929.
I’m working with Shopify’s web pixel integration and subscribing to analytics events (e.g., “page_viewed”). However, the event data object is coming through empty, so I’m unable to access logged-in user information. My goal is to reliably get the currently logged-in user’s details (like email, customer ID, etc.) from within my pixel script.
Is there a recommended way to access the logged-in user data in this context, or a workaround if the event data is empty? Any best practices or examples would be appreciated!
Shopify’s web pixel events often don’t include detailed user info like email or customer ID directly in the event payload due to privacy and security reasons. To reliably get the logged-in user data inside your pixel script, the best practice is to expose this data yourself in the storefront, usually by embedding it in the page’s Liquid template. For example, you can add a JavaScript snippet in your theme’s Liquid files that sets a global variable with the logged-in customer info if available:
Then, your pixel script can read from window.loggedInCustomer to get the customer’s email, ID, or other info. This approach ensures you have access to user data on the client side without relying solely on pixel event payloads, which are often minimal. Just be mindful of privacy and don’t expose sensitive data unnecessarily.
Thank you for the suggestion! Injecting the customer data using Liquid like this
does work well, but it will only work for the specific store where this code is added to the theme files. If you want this to work for all stores using your pixel, each store admin would need to manually add this snippet to their theme’s Liquid files.
For non-technical store admins, this can be quite complex and error-prone, since editing theme code is not always straightforward and can risk breaking the store’s layout if done incorrectly.