Skip to content

ajbosco/segment-config-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

segment-config-go

Github Actions Go Report Card GoDoc

segment-config-go is a Go client library for accessing the Segment Config API.

This library allows you to do the following programmatically:

Authentication

segment-config-go requires a Segment Personal Access Token for authentication. You can generate one with the appropriate access by following the steps in the Segment documentation

Usage

import "github.com/ajbosco/segment-config-go/segment"

Construct a new Segment client with your access token and Segment workspace. For example:

accessToken :=  os.Getenv("ACCESS_TOKEN")
segmentWorkspace :=  os.Getenv("SEGMENT_WORKSPACE")

client := segment.NewClient(accessToken, segmentWorkspace)

Now you can interact with the API to do things like list all sources in your workspace:

sources, err := c.ListSources()

List destinations for a given source:

destinations, err := c.ListDestinations("your-source")

Create a new source:

source, err := c.CreateSource("your-source", "catalog/sources/javascript")

Create a new destination:

source, err := c.CreateDestination("your-source", "google-analytics", "cloud", false, nil)

Create a new tracking plan:

tp := TrackingPlan{
    DisplayName: "Your Tracking Plan",
    Rules: RuleSet{
        Global: Rules{
            Schema: "http://json-schema.org/draft-04/schema#",
            Type:   "object",
            Properties: RuleProperties{
                Context: Properties{
                    Type: "object",
                    Properties: map[string]Property{},
                },
                Properties: Properties{},
                Traits:     Properties{},
            },
        },
        Events: []Event{
            {
                Name:        "Test Event",
                Description: "A simple test event",
                Rules: Rules{
                    Schema: "http://json-schema.org/draft-07/schema#",
                    Type:   "object",
                    Properties: RuleProperties{
                        Traits: Properties{},
                        Properties: Properties{
                            Required: []string{"user_id"},
                            Type:     "object",
                            Properties: map[string]Property{
                                "user_id": {
                                    Description: "unique id of the user",
                                    Type:        []string{"string"},
                                },
                            },
                        },
                    },
                },
            },
        },
    },
}
trackingPlan, err := c.CreateTrackingPlan(tp)

Get an existing tracking plan:

trackingPlan, err := c.GetTrackingPlan("rs_123abc")

List all tracking plans:

trackingPlans, err := c.ListTrackingPlans()

Update an existing tracking plan:

tp := TrackingPlan{
    DisplayName: "Your Tracking Plan",
    Rules: RuleSet{
        Global: Rules{
            Schema: "http://json-schema.org/draft-04/schema#",
            Type:   "object",
            Properties: RuleProperties{
                Context: Properties{
                    Type: "object",
                    Properties: map[string]Property{},
                },
                Properties: Properties{},
                Traits:     Properties{},
            },
        },
        Events: []Event{
            {
                Name:        "Test Event",
                Description: "A simple test event",
                Rules: Rules{
                    Schema: "http://json-schema.org/draft-07/schema#",
                    Type:   "object",
                    Properties: RuleProperties{
                        Traits: Properties{},
                        Properties: Properties{
                            Required: []string{"user_id"},
                            Type:     "object",
                            Properties: map[string]Property{
                                "user_id": {
                                    Description: "unique id of the user",
                                    Type:        []string{"string"},
                                },
                            },
                        },
                    },
                },
            },
        },
    },
}
trackingPlan, err := c.UpdateTrackingPlan("rs_123abc", tp)

Delete an existing tracking plan:

err := client.DeleteTrackingPlan("rs_123abc")

About

A Go client library for the Segment Config API

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •