AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
2.7K members online now
2.7K members online now
Ask questions about filter set-up and issues with using filters in Google Analytics reports
 
Guide Me
star_border
Reply

Segment syntax

Explorer ✭ ☆ ☆
# 1
Explorer ✭ ☆ ☆

I'm trying to find some type of reference on syntax for writing dynamic segments. There are some nuances that never seem clearly explained anywhere.

 

For instance, I'm trying to figure out if these things are different: (ignore the line feeds and tabs, I remove those before I use them)

 

Example 1:

sessions::
    condition::
        ga:dimension7==Logged In

        ,ga:eventAction=~Log

 

Example 2:

sessions::
    condition::
        ga:dimension7==Logged In
    ;condition::

        ga:eventAction=~Log

 

Example 3:

sessions::
    condition::
        ga:dimension7==Logged In

;sessions::
    condition::

        ga:eventAction=~Log

 

 

Don't worry about the scope of the dimensions or what I'm trying to accomplish, these are just for simplicity.  I just want to know if these structures will conceptually return different result sets.

 

 

1 Expert replyverified_user

Re: Segment syntax

Top Contributor
# 2
Top Contributor
There is actually a separate section in the documentation for segments here:
https://developers.google.com/analytics/devguides/reporting/core/v3/segments-feature-reference

...however...it doesn't really said it plain and simple, but example 1 is the better option. In some cases example 3 approach will simply NOT work.

I am ignoring the fact that the first example has a comma and the other two have semicolons...
Mike Sullivan, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Re: Segment syntax

Explorer ✭ ☆ ☆
# 3
Explorer ✭ ☆ ☆
Thanks for the feedback. I've seen that documentation and was hoping there was more. This one is a little better for what I'm looking for:

https://developers.google.com/analytics/devguides/reporting/core/v3/segments#reference

The use of the commas and semicolons is purposeful though. I'm trying to figure out if the various combinations of scope, type, and comma/semicolon can used to produce different result sets. So example 1 would be a segment that meets either criteria, example 2 would meet both criteria, and example 3 would be a union of sessions. In this case, example 1 and 3 are effectively the same, but I'm trying to figure out if this will work as I think it does. I might just have to test it with actual data and known segments.

Again, thanks for the response.

Re: Segment syntax

Top Contributor
# 4
Top Contributor
My point, so it isn't overlooked, is that if the structures are logically the same:
sessions::condition: X ; Y
sessions::condition: X ; condition: Y
sessions::condition: X ; sessions::condition: Y
...then the redundant 'sessions::condition:' should be removed (first option) because GA may actually not work with the second of third case (I forget the error, but it might be a simple syntax error). NOTE: the documentation actually says either way will work, but in practice, the long-form can be problematic.
Mike Sullivan, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Re: Segment syntax

Explorer ✭ ☆ ☆
# 5
Explorer ✭ ☆ ☆
On a random note, I believe I usually bother you via Æ support and thought I'd try the proper channel for once.

In any case, i know what you're saying. For simple conditions such as the examples, I definitely remove redundancies. On the other hand, I'm pretty sure the scope and type can be used somewhat like parentheses to create far more complex segments. I guess I'll just test it out with data.