Skip to content

Commit

Permalink
feat: add method to retrieve value
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokisan committed Mar 9, 2023
1 parent 7d0debc commit 44348bb
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions run_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ga4data

import (
"context"
"fmt"

analyticsdata "google.golang.org/api/analyticsdata/v1beta"
)
Expand Down Expand Up @@ -47,6 +48,46 @@ func (r *RunReportResponse) MergeResponse(resp *analyticsdata.RunReportResponse)
}
}

// DimensionValue :
func (r *RunReportResponse) DimensionValue(row *analyticsdata.Row, column string) analyticsdata.DimensionValue {
return *row.DimensionValues[r.DimensionIndex(column)]
}

// Dimension :
func (r *RunReportResponse) Dimension(row *analyticsdata.Row, column string) string {
return r.DimensionValue(row, column).Value
}

// DimensionIndex :
func (r *RunReportResponse) DimensionIndex(column string) int {
for i, header := range r.DimensionHeaders {
if column == header.Name {
return i
}
}
panic(fmt.Sprintf("column %s is not found", column))
}

// MetricValue :
func (r *RunReportResponse) MetricValue(row *analyticsdata.Row, column string) analyticsdata.MetricValue {
return *row.MetricValues[r.MetricIndex(column)]
}

// Metric :
func (r *RunReportResponse) Metric(row *analyticsdata.Row, column string) string {
return r.MetricValue(row, column).Value
}

// MetricIndex :
func (r *RunReportResponse) MetricIndex(column string) int {
for i, header := range r.MetricHeaders {
if column == header.Name {
return i
}
}
panic(fmt.Sprintf("column %s is not found", column))
}

// RunReport :
func RunReport(
ctx context.Context,
Expand Down

0 comments on commit 44348bb

Please sign in to comment.