A user seeks to randomly assign one of two specific tags to orders in Shopify Flow for an A/B testing experiment. The goal is to include different inserts in shipments and later analyze customer behavior based on which tag was assigned.
Challenge: Flow’s Run Code action doesn’t support math.random() for true randomization.
Proposed Solution: Use the order’s createdAt timestamp to create pseudo-randomness by checking if a portion of it (like seconds) is even or odd. This approach involves:
Extracting the timestamp string (format: “2019-09-07T15:50:00Z”)
Using JavaScript in Run Code to parse and evaluate the value
Assigning tags based on the even/odd result
Status: The discussion remains open with the user seeking clarification on how to manipulate the timestamp string—whether to focus on specific parts (seconds) or convert to Unix/Epoch format for easier even/odd checking.
Summarized with AI on November 1.
AI used: claude-sonnet-4-5-20250929.
I’m wondering if there is a way to ‘randomly’ assign 1 of 2 specific tags to an order using Flow.
The use case here is that we want to randomly send specific inserts in our orders to then see if there’s a difference in these customers’ shopping behaviour later, where we can use the order tag to bucket the customers.
So, we’d have a flow that on order creation sets 1 of N (in our case 2) possible order tags.
That would be all (our logistics partner handles the rest).
Any ideas on how to accomplish this? I know that the Run Code action does not support math.random so any alternative solutions to this are appreciated.
AFAIK this would look like “2019-09-07T15:50:00Z”, correct?
Would you recommend looking at a specific part (i.e. the seconds) of the DateTime, or is there a way to convert to Epoch/Unix timestamp to get a number that is checkable for even/odd?
Not sure exactly what is available in Run code, haven’t used it yet.