Files
insights-go/alias.go
T
zeekay b4e1366340 rebrand: export Insights types instead of PostHog
Rename Go package from posthog to insights across all 80+ files.
Consumers now import as `insights "github.com/hanzoai/insights-go"`
and use insights.Client, insights.Config, insights.Capture, etc.

- Rename posthog.go -> insights.go, posthog_test.go -> insights_test.go
- Update package declaration from posthog to insights in all .go files
- Update SDKName from posthog-go to insights-go
- Update DefaultEndpoint from app.posthog.com to insights.hanzo.ai
- Update all FieldError/ConfigError type strings
- Update User-Agent headers, log prefixes, comments, and docs
- Update JSON test fixtures to match new SDK name
- Update CLI, examples, extras, and sdk_compliance_adapter
- Fix pre-existing go vet warnings (non-constant format strings)
2026-03-13 19:54:58 -07:00

88 lines
1.9 KiB
Go

package insights
import (
"time"
)
var _ Message = (*Alias)(nil)
// This type represents object sent in a alias call
type Alias struct {
// This field is exported for serialization purposes and shouldn't be set by
// the application, its value is always overwritten by the library.
Type string
// Uuid is optional. If not provided, a random UUID will be generated.
Uuid string
Alias string
DistinctId string
Timestamp time.Time
DisableGeoIP bool
}
func (msg Alias) internal() {
panic(unimplementedError)
}
func (msg Alias) Validate() error {
if len(msg.DistinctId) == 0 {
return FieldError{
Type: "insights.Alias",
Name: "DistinctId",
Value: msg.DistinctId,
}
}
if len(msg.Alias) == 0 {
return FieldError{
Type: "insights.Alias",
Name: "Alias",
Value: msg.Alias,
}
}
return nil
}
type AliasInApiProperties struct {
DistinctId string `json:"distinct_id"`
Alias string `json:"alias"`
Lib string `json:"$lib"`
LibVersion string `json:"$lib_version"`
DisableGeoIP bool `json:"$geoip_disable,omitempty"`
}
type AliasInApi struct {
Type string `json:"type"`
Uuid string `json:"uuid"`
Library string `json:"library"`
LibraryVersion string `json:"library_version"`
Timestamp time.Time `json:"timestamp"`
Properties AliasInApiProperties `json:"properties"`
Event string `json:"event"`
}
func (msg Alias) APIfy() APIMessage {
libraryVersion := getVersion()
apified := AliasInApi{
Type: msg.Type,
Uuid: msg.Uuid,
Event: "$create_alias",
Library: SDKName,
LibraryVersion: libraryVersion,
Timestamp: msg.Timestamp,
Properties: AliasInApiProperties{
DistinctId: msg.DistinctId,
Alias: msg.Alias,
Lib: SDKName,
LibVersion: libraryVersion,
DisableGeoIP: msg.DisableGeoIP,
},
}
return apified
}