How to get the customer_id from a ScriptTag

Highlighted
New Member
1 0 1

Hi, We're working on an app that needs to connect our service with stores and match-up shopify customers with our user accounts. We authenticate fine, and can query various APIs, however we're unclear on how our Javascript scriptTag can determine the shopify customer id, in order to pass that to our service. We're also unclear how we might detect when the user transitions from being anonymous to logged into the shopify store.

 

Many thanks,

/charles

PS. Previous posts on the subject seem to be out of date

1 Like
Shopify Staff
Shopify Staff
1558 77 232

You could try using theme code to capture the customer ID with liquid, storing it in a variable for use by your script tag:

 

// Theme code
<script>
  var customerId = {{ customer.id }};
</script>

// ScriptTag
console.log(customerId);

Cheers.

0 Likes