Hi! Could you please explain how Segments work? T...
# ask-questions
d
Hi! Could you please explain how Segments work? The query requires a
user_id
and a `date`: could you explain what the date is for? I could not find any documentation on it. From the FAQ I understand that this is mostly used to correct/filter experiments and limit them to a subset of
user_id
, but I cannot understand the role of the
date
column.
f
We use the date column to determine the date when the user was exposed to your experiment. This is important as GrowthBook supports conversion windows, and also phases, where if you change something in your experiment, and want to only look at the experiment results from time x.
👍 1
d
Thanks, after exploring it some more I understand that the
date
must occur before the experiment
timestamp
for users in this query to be included in the experiment results for the segment. Is that correct? If we go back to the premium users example from the FAQ. What would the date be then? Would it be the moment that they joined premium?
Copy code
SELECT
  user_id
  joined_premium_date AS date
FROM
  my_user_table
WHERE
  account_type = 'premium'
If so, what if they turned off premium since then? Shouldn’t this type of condition require a start and end date (user X had a premium account between date Y and Z)?
f
yes, generally - though you can set negative windows
ah, that depends on how you’ve set up your data
you would want to query your event database rather than your current state
that way you can log ‘signed up for premium’ and ‘churned’
d
OK I see, thanks that’s helpful.
a
Thanks for posting this question. I had the same one and this resolved some confusion. I’m still wondering though about what Olivier wrote “I understand that the
date
must occur before the experiment
timestamp
for users in this query to be included in the experiment results for the segment.” Which
timestamp
is the
date
being compared to/how are they being compared? How does the conversion window (and maybe attribution model) play in?
d
Hi @ambitious-apartment-58735! I was referring to the
date
in the definition of the segment (a segment query must provide a
user_id
and a
date
) and to the timestamp in the definition of the experiment (an experiment must provide a
user_id
, a
timestamp
, an
experiment_id
and a
variation_id
). According to my test, the
date
from the segment must occur before the
timestamp
for a
user_id
to be included in the experiment with the segment.
a
What happens if there are multiple
date
and
timestamp
per user_id?