User Locale in Custom Pixel

Hello there! :wave:

Is there a way to retrieve the current user’s locale in a Custom Pixel (eg. “en” or “it”)?

I tried event.context.navigator.language, but that’s the browser language, which doesn’t always match the current locale.

You could store it in localStorage and then retrieve it.

Thanks @RobDukarski!

Yes, we could do that, but I meant something that works natively without hacks.

Haha, I would not consider it a hack… It is a workaround until there is native support for it. :sweat_smile:

@Alberto_Vena you can make your own event that can use storefront data - but it wont work in checkout. You would have to add this to the theme and then reference in pixels…

Shopify.analytics.publish('customer_extras',
    {
      "event":"customer_extras",
      "customer_id": "{{ customer.id | default: "null" }}",
      "customer_email":"{{ customer.email | md5 | default: "null"  }}",
      "customer_total_spent":"{{ customer.total_spent | default: "null"  }}",
      "customer_orders_count":"{{ customer.orders_count | default: "null"  }}",
      "customer_has_account":"{{ customer.has_account | default: "null"  }}",
      "customer_country": Shopify.country ||"",
      "customer_locale": Shopify.locale || ""
    }
  );

On checkout you can use the checkout_complete event and that has :slight_smile:

  1. event.data.checkout.localization.language.isoCode
  2. event.data.checkout.localization.country.isoCode