Set a server side cookie on shop domain from Shopify APP

Highlighted
New Member
5 0 0

Hello,

Is there a way to set server side first-party cookie from the Shopify APP to avoid Apple's ITP 2.3 ?
We can set client-side first party cookie from the JS placed on the merchant shop, but the limitations is only 24 hours since it is not a server side cookie.

Would like to know If there is a way to place server-side first-party cookie using Shopify APP on the shop domain.

0 Likes
Highlighted

 Apple's ITP 2.3 is a bear. Best guess on a workaround would be to use the Asset API to place a code snippet in the header or footer that sets your cookie from the primary domain. I don't think there's a way around ITP not letting you set a third party cookie from the third party server.

0 Likes
Highlighted
New Member
5 0 0

Have you tried it before ? Can you share the sample ?

0 Likes
Highlighted

No I haven't done this process specifically. It's a bit in depth and requires some technical skills. If you're not a developer or have one on retainer it may be a heavy lift, but her's an overview of the process:

  1. Setup a private app in your Shopify store or use a public one if that's what you're developing.
  2. Give the app read and write permissions for Assets and Themes.
  3. You'll need the the API credentials, theme ID and the file key for the file you are going to inject the code to.
  4. Use any server side scripting language, Postman, or Zapier or Integromat to request the current code in theme.liquid (or any other template on the page(s) you need the cookie set from), and save the code to a variable.
  5. Next, append a javascript snippet that sets the cookie to the above saved code and post a request to write to a theme to overwrite it.
  6. Check the inspector or whatever dev tools you are using to ensure the cookie has been set for the proper length from the main domain for the store.

The snippet may look something like:

<script>
document.cookie = "foo=bar; expires=Thu, 25 Dec 2025 12:00:00 UTC; path=/";
</script>

 

0 Likes
Highlighted
New Member
5 0 0

Isn't it same as setting a cookie from the JS ? We are already setting a cookie from the JS and will have the lifetime of 24 hrs in safari due to ITP 2.3.

I'm looking to set a server side cookie here, Just like how Shopify is setting '_landing_page' , '_orig_referrer' cookies etc. from the server side.

0 Likes