Any way to tie a metaobject to a non logged in customer?

I’m looking for a way to store a piece of data connected to an anonymous site visitor in a place that can be accessed by liquid.
Something like session variables or localstorage, but reachable by liquid and graphql instead of js.
Does such thing exist?
Thanks

I dont think this is possible. What do you want to achieve though? Maybe there is another way to go

1 Like

@Daniel_G you will want to use cart attributes which should stick with the customer until the cart expires or an order is placed.

I use them all the time for conditionally showing/hiding content for non-logged in customers.

4 Likes

Interesting approach. Thanks!
I’ll look into this.

Output the value of your MetaObject Entry in JS and post it to cart.js api as cart attributes, which supports structured data. You would have to reload your window.location to get the benefit of those values being available on your first page.

Thanks. I started going down that rabbit hole. Looks promising. Only storing a metaobject key. Thinking of using both cart attributes and localstorage to refill each other and persist the data for as long as possible.

1 Like

Really depends what you are trying to achieve. If you can explain more in detail might be able to add more to what has already been said.

Haha, I figured using cart attributes was standard for things like this.

I have used them for “password protecting” content, storing date information for things like scheduling deliveries, via URL redirects to add various information to them such as from scanning a QR code at a trade show to know where the customer originated, etc.

They are very useful for storing things in that could then be used in Liquid for other things.

1 Like

Hey folks! I’ve connected with the custom data product team on this and I can confirm there’s currently no direct metaobject support for non-logged in customers. One workaround to explore, as well as cart attributes that was mentioned here, would be storing data in cart metafields.

I have forwarded this as a feature request for the custom data team.

Thanks for the responses and suggestions here so far :slight_smile:

3 Likes

Cart Metafields !! :exploding_head:

We’ve used cart attributes in the past which works well, as you can reference the structured data in Liquid templates (so great for affecting page renders) and it also gets passed to the checkout and the order.

One thing to note: if you rely on cart attributes to affect page renders, remember that cart attributes are wiped if the order was completed. To get around this, we also stored the value in localstorage which would then re-add the cart attribute after the customer completed checkout.

Do cart attributes exist even when there are no items in cart?

Chiming in here - you’ll have a better output if you also state what the problem is instead of just asking for a specific solution because you might have gone down a completely over complicated path when the answer could be super simple and right under your nose.

As other folks have also pointed out, you should also explain what is it that you’re trying to do instead of looking for a specific answer, so the answers are in proper context^

1 Like

Yes. Working on a code bit that would refill the attribute and localstorage from each other, so the value will persist as long as either stays alive.
Thanks

yes! cart attributes exist without items in the cart

2 Likes