Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Web Pixel init data for logged in customer showing undefined ordersCOunt

Solved

Web Pixel init data for logged in customer showing undefined ordersCOunt

jc45
Tourist
3 1 0

I'm checking `init.data.customer` in a custom Web Pixel to get the `ordersCount` for the purpose of detecting repeat customers, but it is coming back as `undefined`. The customer is logged in, has orders, and all fields (`email`, `firstName`, etc.) are populated correctly, except for `ordersCount`.

 

Has `ordersCount` been deprecated or is there another reason why it may be `undefined`?

Accepted Solution (1)

jc45
Tourist
3 1 0

This is an accepted solution.

Following up to share that we were seeing `undefined` because all orders in the accounts we checked were test orders (we were testing on our staging shop), which are not counted. After creating manual orders, we see the value populated correctly for logged in customers.

View solution in original post

Replies 3 (3)

jc45
Tourist
3 1 0

This is an accepted solution.

Following up to share that we were seeing `undefined` because all orders in the accounts we checked were test orders (we were testing on our staging shop), which are not counted. After creating manual orders, we see the value populated correctly for logged in customers.

Schmaxit
Shopify Partner
1 0 0

Hi @jc45, i also got the problem with the value undefined.
The Shopify Support told me to get the data with: event.data?.checkout?.customer?.orders_count in the custom Pixel. But sadly it doesnt work.
Could you tell me how you get the ordersCount in the web pixel?

jc45
Tourist
3 1 0

You can use

 

init.data.customer?.ordersCount

 

In custom pixels, init is a global variable. It's documented here: https://shopify.dev/docs/api/web-pixels-api/standard-api/init