Skip to content

Commit

Permalink
Added options for channels.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kugelschieber committed Nov 25, 2024
1 parent 6c1198f commit 1466222
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/analyzer/filter_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func (options *FilterOptions) UTMTerm(filter *Filter) ([]string, error) {
return options.selectFilterOptions(filter, "utm_term", "session")
}

// Channel returns all channels.
func (options *FilterOptions) Channel(filter *Filter) ([]string, error) {
return options.selectFilterOptions(filter, "channel", "session")
}

// Events returns all event names.
func (options *FilterOptions) Events(filter *Filter) ([]string, error) {
return options.selectFilterOptions(filter, "event_name", "event")
Expand Down
23 changes: 23 additions & 0 deletions pkg/analyzer/filter_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,29 @@ func TestFilterOptions_UTM(t *testing.T) {
assert.Equal(t, "foo", utmTerm[1])
}

func TestFilterOptions_Channel(t *testing.T) {
db.CleanupDB(t, dbClient)
assert.NoError(t, dbClient.SaveSessions([]model.Session{
{Sign: 1, VisitorID: 1, SessionID: 1, Time: util.PastDay(4), Start: util.PastDay(4), Channel: "Paid Social"},
{Sign: 1, VisitorID: 1, SessionID: 1, Time: util.PastDay(2), Start: util.PastDay(2), Channel: "Organic Search"},
{Sign: 1, VisitorID: 1, SessionID: 2, Time: util.PastDay(2), Start: util.PastDay(2), Channel: "Organic Search"},
{Sign: 1, VisitorID: 1, SessionID: 1, Time: util.PastDay(1), Start: util.PastDay(1), Channel: "Direct"},
}))
time.Sleep(time.Millisecond * 100)
analyzer := NewAnalyzer(dbClient)
options, err := analyzer.Options.Channel(nil)
assert.NoError(t, err)
assert.Len(t, options, 3)
assert.Equal(t, "Direct", options[0])
assert.Equal(t, "Organic Search", options[1])
assert.Equal(t, "Paid Social", options[2])
options, err = analyzer.Options.Channel(&Filter{From: util.PastDay(3), To: util.Today()})
assert.NoError(t, err)
assert.Len(t, options, 2)
assert.Equal(t, "Direct", options[0])
assert.Equal(t, "Organic Search", options[1])
}

func TestFilterOptions_Events(t *testing.T) {
db.CleanupDB(t, dbClient)
assert.NoError(t, dbClient.SaveEvents([]model.Event{
Expand Down

0 comments on commit 1466222

Please sign in to comment.