<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tejas Patel on Medium]]></title>
        <description><![CDATA[Stories by Tejas Patel on Medium]]></description>
        <link>https://medium.com/@tejasgpatel?source=rss-e0d9a131f7bc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kq8uu57FL-f9-V5H</url>
            <title>Stories by Tejas Patel on Medium</title>
            <link>https://medium.com/@tejasgpatel?source=rss-e0d9a131f7bc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:43:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tejasgpatel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cookie consent banner using Shopify Customer Privacy API with any React Application]]></title>
            <link>https://medium.com/@tejasgpatel/cookie-consent-banner-using-shopify-customer-privacy-api-with-any-react-application-2f27cb585330?source=rss-e0d9a131f7bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f27cb585330</guid>
            <category><![CDATA[cookie-consent-banner]]></category>
            <category><![CDATA[shopify]]></category>
            <category><![CDATA[headless]]></category>
            <category><![CDATA[customer-privacy-api]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Tejas Patel]]></dc:creator>
            <pubDate>Wed, 02 Oct 2024 02:31:57 GMT</pubDate>
            <atom:updated>2024-10-02T02:31:57.251Z</atom:updated>
            <content:encoded><![CDATA[<p>Shopify released Customer Privacy API to manage customer privacy consent at the start of the year 2024. You can manage privacy policy, cookie banner details, and preferences via the admin panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*K3JjQYOuBiFsiejh8ECtOw.png" /></figure><p>The front-end support is a different story. Default support was available for the Shopify theme and support for the headless Hydrogen framework was released later. Most of the documentation refers to methods using the Hydrogen framework. Here are the quick steps to implement a cookie consent banner for any headless react application.</p><p><strong>Step 1</strong>: Complete privacy setup in the Shopify admin. You can find setup at settings &gt; Customer Privacy. Or search for “Customer Privacy” in the top search bar.</p><p><strong>Step 2</strong>: Install <a href="http://twitter.com/shopify/hydrogen">@shopify/hydrogen</a> and <a href="http://twitter.com/remix">@remix</a>-run/react (dependency for hydrogen shopify package) using npm, yarn, pnpm or your preferred package manager.</p><pre>yarn add @shopify/hydrogen @remix-run/react</pre><p><strong>Step 3: </strong>Add a component to load the cookie banner</p><pre>import {<br>  type VisitorConsentCollected,<br>  useCustomerPrivacy,<br>} from &#39;@shopify/hydrogen&#39;<br>import { Fragment, useEffect } from &#39;react&#39;<br><br>export default function ShopifyCookieConsent() {<br>  const { customerPrivacy, privacyBanner = null } = useCustomerPrivacy({<br>    storefrontAccessToken: &quot;Load from env&quot;,<br>    checkoutDomain: &quot;Load from env&quot;,<br>    onVisitorConsentCollected: (consent: VisitorConsentCollected) =&gt; {<br>      console.log(&#39;Visitor consent collected:&#39;, consent)<br>      // set state to hide the banner<br>      // to remember the collection even after page refresh you can use cookie or local storage<br>    },<br>  })<br><br><br>  useEffect(() =&gt; {<br>    if (customerPrivacy) {<br>      // check if user has analytic consent<br>      console.log(<br>        &#39;User analytic consent:&#39;,<br>        customerPrivacy.analyticsProcessingAllowed()<br>      )<br><br>      // or set tracking consent<br>      // customerPrivacy.setTrackingConsent(<br>      //   {<br>      //     marketing: true,<br>      //     analytics: true,<br>      //     preferences: true,<br>      //     sale_of_data: true,<br>      //   },<br>      //   (data: any) =&gt; {<br>      //     if (data?.error) {<br>      //       console.error(&#39;Error setting tracking consent:&#39;, data.error)<br>      //       return<br>      //     }<br>      //     console.log(&#39;Tracking consent set&#39;)<br>      //   }<br>      // )<br>    }<br><br>    if (privacyBanner ) {<br>      privacyBanner.loadBanner()<br><br>      // or show banner with specific locale and country<br>      // privacyBanner.loadBanner({ locale: language, country: countryCode })<br><br>      // or show consent preferences banner<br>      // privacyBanner.showPreferences()<br><br>      // or show consent preferences banner with specific locale and country<br>      // privacyBanner.showPreferences({locale: &#39;FR&#39;, country: &#39;CA&#39;});<br>    }<br>  }, [customerPrivacy, privacyBanner])<br><br>  return &lt;Fragment&gt;&lt;/Fragment&gt;<br>}</pre><p>Basic code copied from the Hydrogen documentation.</p><p><a href="https://shopify.dev/docs/api/hydrogen/2024-07/hooks/usecustomerprivacy">useCustomerPrivacy</a></p><p><strong>Step 4:</strong> Import or use the component in your root layout or any general component such as header or footer.</p><p>If you have all default settings for the cookie banner in Shopify admin then this should load the Cookie banner as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*_1BA50LxraHRPMRWlehUgg.png" /><figcaption>Example of Cookie Banner Popup in frontend.</figcaption></figure><p>However, there are still more things to do. You should read the collected consent and stop tracking or allow tracking accordingly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f27cb585330" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>