Do custom variable order/indexes need to be constant?

Hi,

I am a little confused about custom variables. I looked at the docs in detail and I am still confused.

I have increased the number to 15

We wish to track a few variables that have a flexible an inconsistent number of values.

For example, let’s say I want to tracker login status and then also a post could have 0 to 3 categories.

Then on some pages I want to tracker with the page is a premium page.

Initially I thought I could do a for loop in php and set the custom variable index flexibily depening on the number of categories like so:

$c=0;
set custom var ++$c, ‘login_status’, $login_status, page
for $cats as $cat {
set custom var ++$c, $cat, page
}
set custom var ++$c, ‘is_premium’, $is_premium, page

BUT, I am getting wierd results with this approach and undercounting.

I am starting to think that the custom variable have to be done in a way that the variables are always using the same indexes

For example

set custom var 1, ‘login_status’, $login_status, page
for $i = 2 … 4 {
if(!empty($cat[$i-1])) set custom var $i, $cat[$i-1], page
}
set custom var 5, ‘is_premium’, $is_premium, page

CAN SOMEONE SHED light on which scenario is correct?

The latter implies that a good deal of attention has to be paid to order and that all pages of a certain type that track a group variables relevant to that page have to have the variable in the similar order so that queries can be performed by pulling actions or visits focused on those variables.

for example

list all actions where (cat)
custom variable 2 = 'hobbies’
or custom variable 3 = 'professional’
or custom variable 4 = ‘fun’

In this case, to make a sane query, it would matter that all cats were using the indexes 2-4, but in any order.

Is that right?

Thanks