analytic

package
v0.0.0-...-c4f7e29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CumulativeUserCountType            = "cumulative.user"
	MonthlyActiveUserCountType         = "monthly.active_user"
	WeeklyActiveUserCountType          = "weekly.active_user"
	DailyActiveUserCountType           = "daily.active_user"
	DailySignupCountType               = "daily.signup"
	DailySignupPageViewCountType       = "daily.page_view.signup"
	DailySignupUniquePageViewCountType = "daily.unique_page_view.signup"
	DailyLoginPageViewCountType        = "daily.page_view.login"
	DailyLoginUniquePageViewCountType  = "daily.unique_page_view.login"
	// nolint: gosec
	DailySignupWithLoginIDCountType = "daily.signup.login_id.%s"
	DailySignupWithOAuthCountType   = "daily.signup.oauth.%s"
	DailySignupAnonymouslyCountType = "daily.signup.anonymous"
)

Variables

View Source
var DailySignupCountTypeByMethods = []*DailySignupCountTypeByMethod{}
View Source
var ErrAnalyticCountNotFound = errors.New("analytic count not found")

Functions

func GetDateListByRangeInclusive

func GetDateListByRangeInclusive(rangeFrom time.Time, rangeTo time.Time, periodical periodicalutil.Type) []time.Time

Types

type AppCollaborator

type AppCollaborator struct {
	AppID  string
	UserID string
}

type AppConfigSource

type AppConfigSource struct {
	AppID    string
	Data     map[string][]byte
	PlanName string
}

type AppDBStore

type AppDBStore struct {
	SQLBuilder  *appdb.SQLBuilder
	SQLExecutor *appdb.SQLExecutor
}

func (*AppDBStore) GetAllUsers

func (s *AppDBStore) GetAllUsers(appID string) ([]*User, error)

func (*AppDBStore) GetNewUserIDs

func (s *AppDBStore) GetNewUserIDs(appID string, rangeFrom *time.Time, rangeTo *time.Time) ([]string, error)

func (*AppDBStore) GetUserCountBeforeTime

func (s *AppDBStore) GetUserCountBeforeTime(appID string, beforeTime *time.Time) (int, error)

func (*AppDBStore) GetUserVerifiedEmails

func (s *AppDBStore) GetUserVerifiedEmails(appID string, userIDs []string) (result map[string]string, err error)

GetUserVerifiedEmails returns userID to email map

type AuditDBReadStore

type AuditDBReadStore struct {
	SQLBuilder  *auditdb.SQLBuilder
	SQLExecutor *auditdb.ReadSQLExecutor
}

func (*AuditDBReadStore) GetAnalyticCountByType

func (s *AuditDBReadStore) GetAnalyticCountByType(
	appID string,
	typ string,
	date *time.Time,
) (*Count, error)

func (*AuditDBReadStore) GetAnalyticCountsByType

func (s *AuditDBReadStore) GetAnalyticCountsByType(
	appID string,
	typ string,
	rangeFrom *time.Time,
	rangeTo *time.Time,
) ([]*Count, error)

GetAnalyticCountsByType get counts by type and date range the provided rangeFrom and rangeTo are inclusive

func (*AuditDBReadStore) GetSumOfAnalyticCountsByType

func (s *AuditDBReadStore) GetSumOfAnalyticCountsByType(
	appID string,
	typ string,
	rangeFrom *time.Time,
	rangeTo *time.Time,
) (int, error)

type AuditDBWriteStore

type AuditDBWriteStore struct {
	SQLBuilder  *auditdb.SQLBuilder
	SQLExecutor *auditdb.WriteSQLExecutor
}

func (*AuditDBWriteStore) UpsertCounts

func (s *AuditDBWriteStore) UpsertCounts(counts []*Count) error

UpsertCounts upsert counts in batches

type Chart

type Chart struct {
	DataSet []*DataPoint `json:"dataset"`
}

type ChartService

type ChartService struct {
	Database       *auditdb.ReadHandle
	AuditStore     *AuditDBReadStore
	Clock          clock.Clock
	AnalyticConfig *config.AnalyticConfig
}

ChartService provides method for the portal to get data for charts

func (*ChartService) GetActiveUserChart

func (s *ChartService) GetActiveUserChart(
	appID string,
	periodical string,
	rangeFrom time.Time,
	rangeTo time.Time,
) (*Chart, error)

func (*ChartService) GetBoundedRange

func (s *ChartService) GetBoundedRange(
	periodical periodicalutil.Type,
	rangeFrom time.Time,
	rangeTo time.Time,
) (newRangeFrom time.Time, newRangeTo time.Time, err error)

GetBoundedRange returns if the given range is valid and the bounded range The range is bounded by the analytic epoch ane the current date

func (*ChartService) GetSignupByMethodsChart

func (s *ChartService) GetSignupByMethodsChart(appID string, rangeFrom time.Time, rangeTo time.Time) (*Chart, error)

func (*ChartService) GetSignupConversionRate

func (s *ChartService) GetSignupConversionRate(appID string, rangeFrom time.Time, rangeTo time.Time) (*SignupConversionRateData, error)

func (*ChartService) GetTotalUserCountChart

func (s *ChartService) GetTotalUserCountChart(appID string, rangeFrom time.Time, rangeTo time.Time) (*Chart, error)

type Count

type Count struct {
	ID    string
	AppID string
	Count int
	Date  time.Time
	Type  string
}

func NewCount

func NewCount(appID string, count int, date time.Time, typ string) *Count

func NewDailySignupWithLoginID

func NewDailySignupWithLoginID(appID string, count int, date time.Time, loginIDType string) *Count

func NewDailySignupWithOAuth

func NewDailySignupWithOAuth(appID string, count int, date time.Time, provider string) *Count

type CountCollector

type CountCollector struct {
	GlobalHandle       *globaldb.Handle
	GlobalDBStore      *GlobalDBStore
	AppDBHandle        *appdb.Handle
	AppDBStore         *AppDBStore
	AuditDBReadHandle  *auditdb.ReadHandle
	AuditDBReadStore   *AuditDBReadStore
	AuditDBWriteHandle *auditdb.WriteHandle
	MeterAuditDBStore  MeterAuditDBReadStore
	AuditDBWriteStore  *AuditDBWriteStore
	AnalyticService    *Service
}

func (*CountCollector) CollectDaily

func (c *CountCollector) CollectDaily(date *time.Time) (updatedCount int, err error)

func (*CountCollector) CollectDailyCountForApp

func (c *CountCollector) CollectDailyCountForApp(appID string, date time.Time, nextDay time.Time) (counts []*Count, redisKey []string, err error)

func (*CountCollector) CollectMonthly

func (c *CountCollector) CollectMonthly(date *time.Time) (updatedCount int, err error)

func (*CountCollector) CollectMonthlyForApp

func (c *CountCollector) CollectMonthlyForApp(appID string, date *time.Time) (counts []*Count, redisKeys []string, err error)

func (*CountCollector) CollectWeekly

func (c *CountCollector) CollectWeekly(date *time.Time) (updatedCount int, err error)

func (*CountCollector) CollectWeeklyForApp

func (c *CountCollector) CollectWeeklyForApp(appID string, date *time.Time) (counts []*Count, redisKeys []string, err error)

type CountResult

type CountResult struct {
	RedisKeys []string
}

CountResult includes the redis keys of the report Expiration should be set to those keys after storing the count to the db

type DailyCountResult

type DailyCountResult struct {
	*CountResult
	ActiveUser           int
	SignupPageView       int
	SignupUniquePageView int
	LoginPageView        int
	LoginUniquePageView  int
}

type DailySignupCountTypeByMethod

type DailySignupCountTypeByMethod struct {
	// MethodName is the name of method
	// It could be LoginIDKeyType or OAuthSSOProviderType. e.g. (email, username, google, anonymous)
	MethodName string
	CountType  string
}

type DataPoint

type DataPoint struct {
	Label string `json:"label"`
	Data  int    `json:"data"`
}

DataPoint represent data point of a chart

type GlobalDBStore

type GlobalDBStore struct {
	SQLBuilder  *globaldb.SQLBuilder
	SQLExecutor *globaldb.SQLExecutor
}

func (*GlobalDBStore) GetAppConfigSource

func (s *GlobalDBStore) GetAppConfigSource(appID string) (*AppConfigSource, error)

func (*GlobalDBStore) GetAppIDs

func (s *GlobalDBStore) GetAppIDs() (appIDs []string, err error)

func (*GlobalDBStore) GetAppOwners

func (s *GlobalDBStore) GetAppOwners(rangeFrom *time.Time, rangeTo *time.Time) ([]*AppCollaborator, error)

func (*GlobalDBStore) GetCollaboratorCount

func (s *GlobalDBStore) GetCollaboratorCount(appID string) (int, error)

type MeterAuditDBReadStore

type MeterAuditDBReadStore interface {
	GetCountByActivityType(appID string, activityType string, rangeFrom *time.Time, rangeTo *time.Time) (int, error)
	QueryPage(appID string, opts audit.QueryPageOptions, pageArgs graphqlutil.PageArgs) ([]*audit.Log, uint64, error)
}

type MonthlyCountResult

type MonthlyCountResult struct {
	*CountResult
	ActiveUser int
}

type OutputCSV

type OutputCSV struct {
	Writer io.Writer
}

func (*OutputCSV) OutputReport

func (o *OutputCSV) OutputReport(ctx context.Context, data *ReportData) error

type OutputGoogleSpreadsheet

type OutputGoogleSpreadsheet struct {
	GoogleOAuthClientCredentialsJSONFilePath string
	GoogleOAuthTokenFilePath                 string
	SpreadsheetOutputMode                    OutputGoogleSpreadsheetMode
	SpreadsheetID                            string
	SpreadsheetRange                         string
}

func (*OutputGoogleSpreadsheet) OutputReport

func (o *OutputGoogleSpreadsheet) OutputReport(ctx context.Context, data *ReportData) error

type OutputGoogleSpreadsheetMode

type OutputGoogleSpreadsheetMode string
const (
	OutputGoogleSpreadsheetModeDefault   OutputGoogleSpreadsheetMode = ""
	OutputGoogleSpreadsheetModeAppend    OutputGoogleSpreadsheetMode = "append"
	OutputGoogleSpreadsheetModeOverwrite OutputGoogleSpreadsheetMode = "overwrite"
)

type PosthogBatchRequest

type PosthogBatchRequest struct {
	APIKey string            `json:"api_key"`
	Batch  []json.RawMessage `json:"batch,omitempty"`
}

type PosthogCredentials

type PosthogCredentials struct {
	Endpoint string
	APIKey   string
}

type PosthogGroup

type PosthogGroup struct {
	ProjectID         string
	MAU               int
	UserCount         int
	CollaboratorCount int
	ApplicationCount  int
	ProjectPlan       string
}

type PosthogIntegration

type PosthogIntegration struct {
	PosthogCredentials *PosthogCredentials
	Clock              clock.Clock
	GlobalHandle       *globaldb.Handle
	GlobalDBStore      *GlobalDBStore
	AppDBHandle        *appdb.Handle
	AppDBStore         *AppDBStore
	Logger             PosthogLogger
	ReadCounterStore   ReadCounterStore
}

func (*PosthogIntegration) Batch

func (p *PosthogIntegration) Batch(endpoint *url.URL, events []json.RawMessage) error

func (*PosthogIntegration) SetGroupProperties

func (p *PosthogIntegration) SetGroupProperties() error

func (*PosthogIntegration) SetUserProperties

func (p *PosthogIntegration) SetUserProperties(portalAppID string) error

type PosthogLogger

type PosthogLogger struct{ *log.Logger }

func NewPosthogLogger

func NewPosthogLogger(lf *log.Factory) PosthogLogger

type ProjectHourlyReport

type ProjectHourlyReport struct {
	GlobalHandle  *globaldb.Handle
	GlobalDBStore *GlobalDBStore
	AppDBHandle   *appdb.Handle
	AppDBStore    *AppDBStore
}

func (*ProjectHourlyReport) Run

func (r *ProjectHourlyReport) Run(options *ProjectHourlyReportOptions) (data *ReportData, err error)

type ProjectHourlyReportOptions

type ProjectHourlyReportOptions struct {
	Time *time.Time
}

type ProjectMonthlyReport

type ProjectMonthlyReport struct {
	GlobalHandle  *globaldb.Handle
	GlobalDBStore *GlobalDBStore
	AuditDBHandle *auditdb.ReadHandle
	AuditDBStore  *AuditDBReadStore
}

func (*ProjectMonthlyReport) Run

func (r *ProjectMonthlyReport) Run(options *ProjectMonthlyReportOptions) (data *ReportData, err error)

type ProjectMonthlyReportOptions

type ProjectMonthlyReportOptions struct {
	Year  int
	Month int
}

type ProjectWeeklyReport

type ProjectWeeklyReport struct {
	GlobalHandle      *globaldb.Handle
	GlobalDBStore     *GlobalDBStore
	AppDBHandle       *appdb.Handle
	AppDBStore        *AppDBStore
	AuditDBHandle     *auditdb.ReadHandle
	MeterAuditDBStore MeterAuditDBReadStore
	AuditDBStore      *AuditDBReadStore
}

func (*ProjectWeeklyReport) Run

func (r *ProjectWeeklyReport) Run(options *ProjectWeeklyReportOptions) (data *ReportData, err error)

type ProjectWeeklyReportOptions

type ProjectWeeklyReportOptions struct {
	Year        int
	Week        int
	PortalAppID string
}

type ReadCounterStore

type ReadCounterStore interface {
	GetDailyPageViewCount(
		appID config.AppID,
		pageType meter.PageType,
		date *time.Time,
	) (pageView int, uniquePageView int, redisKeys []string, err error)
	GetDailyActiveUserCount(appID config.AppID, date *time.Time) (count int, redisKey string, err error)
	GetWeeklyActiveUserCount(appID config.AppID, year int, week int) (count int, redisKey string, err error)
	GetMonthlyActiveUserCount(appID config.AppID, year int, month int) (count int, redisKey string, err error)
	SetKeysExpire(keys []string, expiration time.Duration) error
}

type ReportData

type ReportData struct {
	Header []interface{}
	Values [][]interface{}
}

type Service

type Service struct {
	ReadCounter ReadCounterStore
}

func (*Service) GetDailyCountResult

func (s *Service) GetDailyCountResult(appID config.AppID, date *time.Time) (*DailyCountResult, error)

func (*Service) GetMonthlyCountResult

func (s *Service) GetMonthlyCountResult(appID config.AppID, year int, month int) (*MonthlyCountResult, error)

func (*Service) GetWeeklyCountResult

func (s *Service) GetWeeklyCountResult(appID config.AppID, year int, week int) (*WeeklyCountResult, error)

func (*Service) SetKeysExpire

func (s *Service) SetKeysExpire(keys []string, expiration time.Duration) error

type SignupConversionRateData

type SignupConversionRateData struct {
	TotalSignup               int     `json:"totalSignup"`
	TotalSignupUniquePageView int     `json:"totalSignupUniquePageView"`
	ConversionRate            float64 `json:"conversionRate"`
}

type SignupCountResult

type SignupCountResult struct {
	TotalCount           int
	CountByLoginID       map[string]int
	CountByOAuthProvider map[string]int
	AnonymousCount       int
}

type User

type User struct {
	ID    string
	Email string
}

type UserWeeklyReport

type UserWeeklyReport struct {
	GlobalHandle  *globaldb.Handle
	GlobalDBStore *GlobalDBStore
	AppDBHandle   *appdb.Handle
	AppDBStore    *AppDBStore
}

func (*UserWeeklyReport) Run

func (r *UserWeeklyReport) Run(options *UserWeeklyReportOptions) (data *ReportData, err error)

type UserWeeklyReportOptions

type UserWeeklyReportOptions struct {
	Year        int
	Week        int
	PortalAppID string
}

type WeeklyCountResult

type WeeklyCountResult struct {
	*CountResult
	ActiveUser int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL