Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
I'm struggling to retrieve user consent data from within Customer Events (custom pixel) through Customer Privacy API, which doesn't seem to be working for some reason.
I've tried collecting it using the visitorConsentCollected event like this:
window.Shopify.customerPrivacy.subscribe('visitorConsentCollected', (event) => {
customerPrivacyStatus = event.customerPrivacy;
But I keep getting Shopify is undefined.
I've also tried wrapping the entire code Shopify's loadFeatures:
window.Shopify.loadFeatures(
[
{
name: 'consent-tracking-api',
version: '0.1',
},
],
error => {
if (error) {
// Rescue error
}
// If error is false, the API has loaded and ready to use!
},
);
Yet without success (Shopify still undefined).
I've also tried to modify the timing of the execution of the loadCustomerPrivacyAPI() function (containing the visitorConsentCollected event subscription) like this:
if (document.readyState === 'loading') {
document.addEventListener("DOMContentLoaded", function() {
initializeGTM();
loadCustomerPrivacyAPI();
});
} else {
initializeGTM();
loadCustomerPrivacyAPI();
}
But without success.
What am I missing here?
In the official documentation, they say you can call the
customerPrivacy.subscribe()
just like this, but it doesn't work.
In the code example, they are prepending it with
api.
but don't mention anywhere what that actually is.
Any help would be greatly appreciated!