analytic

package
v0.0.0-...-ee57881 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 38 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(ctx context.Context, appID string) ([]*User, error)

func (*AppDBStore) GetNewUserIDs

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

func (*AppDBStore) GetUserCountBeforeTime

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

func (*AppDBStore) GetUserVerifiedEmails

func (s *AppDBStore) GetUserVerifiedEmails(ctx context.Context, 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(
	ctx context.Context,
	appID string,
	typ string,
	date *time.Time,
) (*Count, error)

func (*AuditDBReadStore) GetAnalyticCountsByType

func (s *AuditDBReadStore) GetAnalyticCountsByType(
	ctx context.Context,
	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(
	ctx context.Context,
	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(ctx context.Context, 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(
	ctx context.Context,
	appID string,
	periodical string,
	rangeFrom time.Time,
	rangeTo time.Time,
) (*Chart, error)

GetActiveUserChart acquires connection.

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(ctx context.Context, appID string, rangeFrom time.Time, rangeTo time.Time) (*Chart, error)

GetSignupByMethodsChart acquires connection.

func (*ChartService) GetSignupConversionRate

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

GetSignupConversionRate acquires connection.

func (*ChartService) GetTotalUserCountChart

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

GetTotalUserCountChart acquires connection.

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(ctx context.Context, date *time.Time) (updatedCount int, err error)

func (*CountCollector) CollectDailyCountForApp

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

func (*CountCollector) CollectMonthly

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

func (*CountCollector) CollectMonthlyForApp

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

func (*CountCollector) CollectWeekly

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

func (*CountCollector) CollectWeeklyForApp

func (c *CountCollector) CollectWeeklyForApp(ctx context.Context, 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(ctx context.Context, appID string) (*AppConfigSource, error)

func (*GlobalDBStore) GetAppIDs

func (s *GlobalDBStore) GetAppIDs(ctx context.Context) (appIDs []string, err error)

func (*GlobalDBStore) GetAppOwners

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

func (*GlobalDBStore) GetCollaboratorCount

func (s *GlobalDBStore) GetCollaboratorCount(ctx context.Context, appID string) (int, error)

type MeterAuditDBReadStore

type MeterAuditDBReadStore interface {
	GetCountByActivityType(ctx context.Context, appID string, activityType string, rangeFrom *time.Time, rangeTo *time.Time) (int, error)
	QueryPage(ctx context.Context, 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 PosthogHTTPClient

type PosthogHTTPClient struct {
	*http.Client
}

func NewPosthogHTTPClient

func NewPosthogHTTPClient() PosthogHTTPClient

type PosthogIntegration

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

func (*PosthogIntegration) Batch

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

func (*PosthogIntegration) SetGroupProperties

func (p *PosthogIntegration) SetGroupProperties(ctx context.Context) error

func (*PosthogIntegration) SetUserProperties

func (p *PosthogIntegration) SetUserProperties(ctx context.Context, 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

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

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

type ProjectWeeklyReportOptions

type ProjectWeeklyReportOptions struct {
	Year        int
	Week        int
	PortalAppID string
}

type ReadCounterStore

type ReadCounterStore interface {
	GetDailyPageViewCount(
		ctx context.Context,
		appID config.AppID,
		pageType meter.PageType,
		date *time.Time,
	) (pageView int, uniquePageView int, redisKeys []string, err error)
	GetDailyActiveUserCount(ctx context.Context, appID config.AppID, date *time.Time) (count int, redisKey string, err error)
	GetWeeklyActiveUserCount(ctx context.Context, appID config.AppID, year int, week int) (count int, redisKey string, err error)
	GetMonthlyActiveUserCount(ctx context.Context, appID config.AppID, year int, month int) (count int, redisKey string, err error)
	SetKeysExpire(ctx context.Context, 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(ctx context.Context, appID config.AppID, date *time.Time) (*DailyCountResult, error)

func (*Service) GetMonthlyCountResult

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

func (*Service) GetWeeklyCountResult

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

func (*Service) SetKeysExpire

func (s *Service) SetKeysExpire(ctx context.Context, 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(ctx context.Context, 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