Hi, question about user dimensions in GB: What ha...
# ask-questions
p
Hi, question about user dimensions in GB: What happens when a dimension changes its value for a given identifier? Let's say I use
anonymous_id
(based on device_id) as identifier, and have a dimension
visitor_type
which can have the values "new", "returning", or "customer". The dimension first has the value "new", but on a later visit it will be "returning", because the
anonymous_id
was recognized. So the user becomes part of the experiment with
visitor_type
= "new", and returns and then sees the experiment, but now as
visitor_type
= "returning" How does GB deal with this when I segment the experiment result data by
visitor_type
?
h
Great question. This is definitely a blind spot in the app. Because
timestamp
isn't a required field in the User Dimension definition, we have to use some arbitrary rule making to select one user dimension per user (right now we just use
MAX
). On your end, the best way to handle this would be to define your User Dimension using SQL Template variables where you define your user dimension yourself to get the latest record per user that has a
timestamp < {{startDate}}
so that you can ensure all dimensions are pre-experiment (best for bias).
You could do something like the following:
Copy code
WITH visitor_types AS (
SELECT
  anonymous_id,
  visitor_type,
  ROW_NUMBER() OVER (PARTITION BY anonymous_id ORDER BY timestamp DESC) AS rn
FROM
  dim_table
WHERE
  timestamp > DATE_SUB({{startDate}}, INTERVAL 7 DAY) AND timestamp < {{startDate}}
)

SELECT
  anonymous_id,
  visitor_type
FROM visitor_types
WHERE rn = 1
p
Thank you Luke, I'll try that