Skip to content

wacul/gasegment

Repository files navigation

Google Analytics segment definition Parser and Serializer

Example

package main

import (
	"fmt"

	"github.com/wacul/gasegment"
)

func main() {
	// parse
	segments, err := gasegment.Parse("users::condition::ga:pagePath==/abc")
	if err != nil {
		panic(err)
	}

	// modify
	segments[0].Scope = gasegment.SessionScope
	segments[0].Condition.AndExpression[0][0].Operator = gasegment.NotEqual
	segments[0].Condition.AndExpression[0][0].Value = "cde"

	// stringify
	fmt.Println(segments.DefString())
}

Commandline

$ go get -v github.com/wacul/gasegment/cmd/gasegment
$ echo "sessions::condition::ga:medium==referral"  | gasegment
{
  "name": "-",
  "sessionSegment": {
    "segmentFilters": [
      {
        "simpleSegment": {
          "orFiltersForSegment": [
            {
              "segmentFilterClauses": [
                {
                  "dimensionFilter": {
                    "dimensionName": "ga:medium",
                    "expressions": [
                      "referral"
                    ],
                    "operator": "EXACT"
                  }
                }
              ]
            }
          ]
        }
      }
    ]
  }
}