Get customer email or id in script tag

Solved
user072319
Excursionist
64 0 4

Hello there,

I want to retrieve shopify store's logged in customer email or id in a script tag. I tried with:

window.onload = function() {
  var customerId = __st.cid;
  console.log("customerId: "+customerId);
};

and it didn't console printed anything.

And I tried with the following code:

var customerId = {{customer.id}};
console.log("customerId: "+customerId);

But this gave console error for }
What is the correct way to get the customer id/email?

0 Likes
SBD_
Shopify Staff
Shopify Staff
1079 145 192

This is an accepted solution.

Hey @user072319,

 

ScriptTags can't read these variables. You'll need to pass them to your script from a theme file.

 

E.g. theme.liquid:

 

 

<script>
someScript('{{ customer.id }}')
</script>

 

0 Likes
dylanpierce
Shopify Partner
138 2 42

Hi @SBD_ my app and I'm sure many others rely on the currently logged in customer context in order to function properly.

By requiring merchants to update their theme's liquid with a line to inject the customer server variable into a javascript variable seems hacky at best.

This practice will lead to confused merchants at best. Is there any other way of accessing the currently logged in user by ID in the frontend alone? 

Founder of Verdict - Anti-Fraud Apps for Shopify
  • Blockade - Easily block countries, IP addresses, VPNs
  • Real ID - Verify your customer's real IDs easily & securely
0 Likes
SBD_
Shopify Staff
Shopify Staff
1079 145 192

Hey @dylanpierce 

Unfortunately not. An awkward workaround is required. This is a known pain point being tracked internally.

 

0 Likes
dylanpierce
Shopify Partner
138 2 42

Hi @SBD_ thanks for at least responding. Delivering bad news is no fun.

Can we at least get some visibility into tracking these issues?

In the past 2 weeks alone I've encountered the following issues:

* AppBridge v2 rollout botched and unusable

* A threat in my Partner Dashboard that my app will be pulled from the store due to a warning about an API deprecation I never received

* Now this

Myself and other app developers need a bit more transparency than what we're getting now. Just giving my honest feedback here. I want to continue to develop & extend Shopify, but the 20% cut for this level of support isn't really adding up.

Founder of Verdict - Anti-Fraud Apps for Shopify
  • Blockade - Easily block countries, IP addresses, VPNs
  • Real ID - Verify your customer's real IDs easily & securely
0 Likes
SBD_
Shopify Staff
Shopify Staff
1079 145 192

Thanks for the feedback and sorry for the friction.

- AppBridge v2 rollout botched and unusable

Thanks for reporting this. It should now be resolved. Let me know if otherwise.

A threat in my Partner Dashboard that my app will be pulled from the store due to a warning about an API deprecation I never received

I can look into this one - can you please DM me details?

 

0 Likes
dylanpierce
Shopify Partner
138 2 42

@SBD_ sure but I'll post here too because it's already talked about by other developers in the Slack channel and here on the forums:

https://community.shopify.com/c/Shopify-APIs-SDKs/Removing-discount-allocation-method-quot-one-quot/...

Finally a Shopify rep has communicated with us publicly that it was a false positive warning. Still, we were all scrambling to figure out what was going on.

I had customer support end tell me hours were over for the day but I had just received this notice minutes before. This is alarming.

You guys must be going through some crazy growing pains right now. I hope you find a way to keep delivering features without constant regressions like we've seen seeing lately.

Founder of Verdict - Anti-Fraud Apps for Shopify
  • Blockade - Easily block countries, IP addresses, VPNs
  • Real ID - Verify your customer's real IDs easily & securely
0 Likes