Rest assured, Context segment rules can seamlessly integrate with Shopify stores that utilize third-party authentication. This allows for a streamlined user experience without compromising on the safety and security of your online store.
To integrate your third-party provider, you will need to add some JavaScript to your Shopify layout file, preferably within the <head>
tag. This will provide Context with the Shopify customer ID (for Shopify segments) and/or the customer's email address (for Klaviyo segments) to identify the current shopper.
Here’s an example of what it could look like. Note that the code includes a safeguard to ensure your site doesn’t break if Context isn’t available.
<script>
document.addEventListener("DOMContentLoaded", () => {
const customer = window.relevantbits?.context?.customer;
if (customer) {
customer.id = user.shopifyCustomerId;
customer.email = user.email;
}
});
</script>