Skip to content

Instantly share code, notes, and snippets.

@vishnuixm
Last active January 9, 2024 11:57
Show Gist options
  • Save vishnuixm/a547c4990310d83de42ed96442ffa1b7 to your computer and use it in GitHub Desktop.
Save vishnuixm/a547c4990310d83de42ed96442ffa1b7 to your computer and use it in GitHub Desktop.
Shopify CustomerLabs profile unification

Add if cart token is coming on webhook

attaching shopify_cart_token as external id

browser.cookie.get('cart').then(function(cart_token){
    fetch("//io.v2.customerlabs.co/externalIds?shopify_cart_token=" + cart_token + "&id=" + window.CLabsgbVar.appId + "&uid=" + window.CLabsgbVar.generalProps.uid);
}).catch(function(e){
   console.log("clabs cart token collection issue", e)
});

Add if cart token is not coming on webhook - theme.liquid

fetch('/cart/update.js', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: 'attributes[customerlabs_id]=' + window.CLabsgbVar.generalProps.uid
}).then(function (response) {
  return response.json();
}).then(function (data) {
  console.log('Success:', data);
}).catch(function (error) {
  console.error('Error:', error);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment