Skip to content

Commit

Permalink
Added regional statistics, removed DNT, updated dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kugelschieber committed May 24, 2024
1 parent 800f578 commit e8bfb5a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.3.0

* added regional statistics
* removed DNT
* updated dependencies

## 2.2.0

This update contains breaking changes!
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/emvi/null v1.3.1
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
20 changes: 12 additions & 8 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
browserEndpoint = "/api/v1/statistics/browser"
browserVersionEndpoint = "/api/v1/statistics/browser/version"
countryEndpoint = "/api/v1/statistics/country"
regionEndpoint = "/api/v1/statistics/region"
cityEndpoint = "/api/v1/statistics/city"
platformEndpoint = "/api/v1/statistics/platform"
screenEndpoint = "/api/v1/statistics/screen"
Expand Down Expand Up @@ -171,10 +172,6 @@ func (client *Client) PageView(r *http.Request, options *PageViewOptions) error

// Event sends an event to Pirsch for given http.Request and options.
func (client *Client) Event(name string, durationSeconds int, meta map[string]string, r *http.Request, options *PageViewOptions) error {
if r.Header.Get("DNT") == "1" {
return nil
}

if options == nil {
options = new(PageViewOptions)
}
Expand All @@ -189,10 +186,6 @@ func (client *Client) Event(name string, durationSeconds int, meta map[string]st

// Session keeps a session alive for the given http.Request and options.
func (client *Client) Session(r *http.Request, options *PageViewOptions) error {
if r.Header.Get("DNT") == "1" {
return nil
}

if options == nil {
options = new(PageViewOptions)
}
Expand Down Expand Up @@ -511,6 +504,17 @@ func (client *Client) Country(filter *Filter) ([]CountryStats, error) {
return stats, nil
}

// Region returns region statistics.
func (client *Client) Region(filter *Filter) ([]RegionStats, error) {
stats := make([]RegionStats, 0)

if err := client.performGet(client.getStatsRequestURL(regionEndpoint, filter), client.requestRetries, &stats); err != nil {
return nil, err
}

return stats, nil
}

// City returns city statistics.
func (client *Client) City(filter *Filter) ([]CityStats, error) {
stats := make([]CityStats, 0)
Expand Down
12 changes: 11 additions & 1 deletion pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Filter struct {
EventMeta map[string]string `json:"-"`
Language []string `json:"language,omitempty"`
Country []string `json:"country,omitempty"`
Region []string `json:"region,omitempty"`
City []string `json:"city,omitempty"`
Referrer []string `json:"referrer,omitempty"`
ReferrerName []string `json:"referrer_name,omitempty"`
Expand Down Expand Up @@ -356,10 +357,19 @@ type CountryStats struct {
CountryCode string `json:"country_code"`
}

// RegionStats is the result type for region statistics.
type RegionStats struct {
MetaStats
CountryCode string `json:"country_code"`
Region string `json:"region"`
}

// CityStats is the result type for city statistics.
type CityStats struct {
MetaStats
City string `json:"city"`
CountryCode string `json:"country_code"`
Region string `json:"region"`
City string `json:"city"`
}

// BrowserStats is the result type for browser statistics.
Expand Down

0 comments on commit e8bfb5a

Please sign in to comment.