analytics

package
v0.0.0-...-0fffe9f Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XSearchQuery                    = "X-Search-Query"
	XSearchID                       = "X-Search-Id"
	XTimestamp                      = "X-timestamp"
	XSearchFilters                  = "X-Search-Filters"
	XSearchClickObjectID            = "X-Search-Click-Object"
	XSearchClick                    = "X-Search-Click"
	XSearchClickPosition            = "X-Search-ClickPosition"
	XSearchSuggestionsClick         = "X-Search-Suggestions-Click"
	XSearchSuggestionsClickPosition = "X-Search-Suggestions-ClickPosition"
	XSearchConversion               = "X-Search-Conversion"
	XSearchCustomEvent              = "X-Search-CustomEvent"
	XSearchState                    = "X-Search-State"
	XUserID                         = "X-User-Id"
)

Custom headers

View Source
const (
	CustomEventsPrefix = "c_"
)

Variables

View Source
var InsightConfig = []InsightConfigType{
	{
		ID: NoResults,
		Insight: Insight{
			Title:       `"There are "+FormatNumber(ToFloat(TotalNoResultsSearches))+" no results searches"`,
			Description: `"No results searches create a poor user experience for your users."`,
			Condition:   "TotalNoResultsSearches > 0",
			ShortLink:   links.NoResultsSearches.ShortLink,
			Recommendations: []Recommendation{
				{
					Title:       "Language Settings",
					Description: "Set the language, stemming and stop words settings in the Language settings.",
					ShortLink:   links.Language.ShortLink,
				},
				{
					Title:       "Search Settings",
					Description: "Ensure that the searchable fields are set. You can also enable the typo tolerance setting.",
					ShortLink:   links.SearchSettings.ShortLink,
				},
				{
					Title:       "Synonyms",
					Description: "Map the no results search terms to data that's present in your index.",
					ShortLink:   links.Synonyms.ShortLink,
				},
				{
					Title:       "Query Rules",
					Description: "Create a query rule to promote results for the no results search terms.",
					ShortLink:   links.Rules.ShortLink,
				},
			},
		},
	},
	{
		ID: LowClicks,
		Insight: Insight{
			Title:       `"Less than "+AvgClickRate+"% of your searches receive a click"`,
			Description: `"Your searches saw an average click rate of "+AvgClickRate+"%."`,
			Condition:   "AvgClickRate > 0 and AvgClickRate <= 5",
			Recommendations: []Recommendation{
				{
					Title:       "Language Settings",
					Description: "Set the language, stemming and stop words settings in the Language settings.",
					ShortLink:   links.Language.ShortLink,
				},
				{
					Title:       "Search Settings",
					Description: "Ensure that the searchable fields are set correctly and weighted appropriately.",
					ShortLink:   links.SearchSettings.ShortLink,
				},
				{
					Title:       "Query Rules",
					Description: "Create a query rule to promote more relevant results.",
					ShortLink:   links.Rules.ShortLink,
				},
			},
		},
	},
	{
		ID: LowSuggestionsClicks,
		Insight: Insight{
			Title:       `"Less than "+AvgSuggestionsClickRate+"% of your auto suggestion searches receive a click"`,
			Description: `"Your auto suggestion searches saw an average click rate of "+AvgSuggestionsClickRate+"%."`,
			Condition:   "AvgSuggestionsClickRate > 0 and AvgSuggestionsClickRate <= 5",
			Recommendations: []Recommendation{
				{
					Title:       "Language Settings",
					Description: "Set the language, stemming and stop words settings in the Language settings.",
					ShortLink:   links.Language.ShortLink,
				},
				{
					Title:       "Search Settings",
					Description: "Ensure that the searchable fields are set correctly and weighted appropriately.",
					ShortLink:   links.SearchSettings.ShortLink,
				},
				{
					Title:       "Query Rules",
					Description: "Create a query rule to promote more relevant results.",
					ShortLink:   links.Rules.ShortLink,
				},
				{
					Title:       "Query suggestions",
					Description: "Set query suggestions to show suggestions recommendations based on analytics data.",
					ShortLink:   links.QuerySuggestions.ShortLink,
				},
			},
		},
	},
	{
		ID: AvgClickPosition,
		Insight: Insight{
			Title:       `"The average click position for your results is "+AvgClickPosition`,
			Description: `"A higher value for average click position indicates that your users need to scroll through before they find what they are looking for."`,
			Condition:   "AvgClickPosition >= 5",
			Recommendations: []Recommendation{
				{
					Title:       "Search Settings",
					Description: "Ensure that the searchable fields are set correctly and weighted appropriately. You can test with other search settings.",
					ShortLink:   links.SearchSettings.ShortLink,
				},
			},
		},
	},
	{
		ID: PopularSearches,
		Insight: Insight{
			Title:       `"You have "+FormatNumber(ToFloat(PopularSearches))" popular searches"`,
			Description: `"Congrats! These terms are searched for at least 100 times by your users."`,
			Condition:   "PopularSearches > 0",
			ShortLink:   links.PopularSearches.ShortLink,
			Recommendations: []Recommendation{
				{
					Title:       "Query Rules",
					Description: "Create a query rule for these terms to merchandise other items.",
					ShortLink:   links.Rules.ShortLink,
				},
			},
		},
	},
	{
		ID: PopularSearchesWithLowClicks,
		Insight: Insight{
			Title:       `"Less than "+AvgClickRatePopularSearches+"% of your popular searches receive a click"`,
			Description: `"On an average, your popular searches saw a click rate of "+AvgClickRatePopularSearches+"%."`,
			Condition:   "PopularSearches > 0 and AvgClickRatePopularSearches <= 5",
			ShortLink:   links.PopularSearches.ShortLink,
			Recommendations: []Recommendation{
				{
					Title:       "Language Settings",
					Description: "Set the language, stemming and stop words settings in the Language settings.",
					ShortLink:   links.Language.ShortLink,
				},
				{
					Title:       "Search Settings",
					Description: "Ensure that the searchable fields are set correctly and weighted appropriately.",
					ShortLink:   links.SearchSettings.ShortLink,
				},
				{
					Title:       "Query Rules",
					Description: "Create a query rule to promote more relevant results.",
					ShortLink:   links.Rules.ShortLink,
				},
			},
		},
	},
	{
		ID: LongTailSearches,
		Insight: Insight{
			Title:           `"Analyze the long tail search terms"`,
			Description:     `"Long-tail searches often tell you what your power users are looking for."`,
			Condition:       "AvgQueryLength >= 4",
			Recommendations: []Recommendation{},
		},
	},
	{
		ID: BounceRate,
		Insight: Insight{
			Title:       `"Your search bounce rate is "+AvgBounceRate+"%"`,
			Description: `"Bounce rate indicates sessions where a user left without interacting with the search."`,
			Condition:   "AvgBounceRate > 50",
			Recommendations: []Recommendation{
				{
					Title:       "Improve your search experience",
					Description: "You can use external tools such as Hotjar to qualitatively understand the gaps in your search experience.",
				},
			},
		},
	},
	{
		ID: HighResponseTime,
		Insight: Insight{
			Title:       `FormatNumber(ToFloat(HighResponseTimeSearches))+" searches took more than a second"`,
			Description: `"At least 10% of your total searches are taking more than a second to return. A lower response time provides a better user experience."`,
			Condition:   "HighResponseTimeSearches > 0",
			Recommendations: []Recommendation{
				{
					Title:       "Review Results Settings",
					Description: "You can set what fields to return and optimize your highlighting settings to improve the search response time.",
					ShortLink:   links.ResultSettings.ShortLink,
				},
				{
					Title:       "Review Index settings",
					Description: "An optimal shard and replica setting can provide a better search response time.",
					ShortLink:   links.IndexSettings.ShortLink,
				},
			},
		},
	},
	{
		ID: Error500,
		Insight: Insight{
			Title:       `FormatNumber(ToFloat(InternalServerErrors))+" searches returned an internal server error"`,
			Description: `"Internal server errors indicate an issue with the underlying ElasticSearch service."`,
			Condition:   "InternalServerErrors > 0",
			ShortLink:   links.RequestLogs.ShortLink,
			Recommendations: []Recommendation{
				{
					Title:       "Optimize your ElasticSearch configuration",
					Description: "Check with your service provider on what can be done to improve your search infrastructure's availability. If your search volume is growing, you may also want to look at upgrading the search servers.",
				},
			},
		},
	},
	{
		ID: Error400,
		Insight: Insight{
			Title:       `FormatNumber(ToFloat(BadRequestErrors))+" searches failed due to a client error"`,
			Condition:   "BadRequestErrors > 0",
			Description: `"Your searches failed due to a bad request or an authentication error."`,
			ShortLink:   links.RequestLogs.ShortLink,
			Recommendations: []Recommendation{
				{
					Title: "Analyze your logs for errors.",
				},
			},
		},
	},
}

InsightConfig can be used to configure the insights and recommendations. Please follow the instructions carefully before editing: 1. Insight title must be a valid expression from `expr` library, for example: '`"There are "+TotalNoResultsSearches+" no result searches"`'. 2. Insight is driven by the `Condition` property which is also an expression. 3. Check the `DetailedSummary` struct in `plugins/analytics/util.go` to know the env. variables available for expression. 4. You can also use markdown for the string fields for eg. 'Get the [reactivesearch.io](reactivesearch.io) support plan' 5. The order of the insights and recommendations will be determined from this config, so any changes in the order will affect the order in the UI.

View Source
var PreDefinedTermFilters = [...]string{"user_id", "ip"}

Need to define separately so we can decide whether to apply custom event prefix in field or not while querying ES.

Functions

func AddEventPrefix

func AddEventPrefix(key string) string

Adds the prefix from custom event field

func ApplyCustomEventsEs7

func ApplyCustomEventsEs7(query *es7.BoolQuery, filters map[string]interface{})

ApplyCustomEventsEs7 applies the custom events to ES7 query

func FetchDocumentForSource

func FetchDocumentForSource(index string, documentId string) (map[string]interface{}, error)

FetchDocumentForSource will fetch the document based on the passed details

func GenerateRecentDocId

func GenerateRecentDocId(documentId, index string) string

GenerateRecentDocId will generate the recent document ID with the passed values.

func GetAnalyticsIndex

func GetAnalyticsIndex() string

func GetCustomFilters

func GetCustomFilters(values url.Values) map[string]interface{}

GetCustomFilters will parse the custom filters from the query params map

func GetDocumentSuggestionsIndex

func GetDocumentSuggestionsIndex() string

func HasSearchTypeOfQuery

func HasSearchTypeOfQuery(rsRequestBody *querytranslate.RSQuery) bool

Returns true if request body has at least one type search query

func IsAnalyticsEnabled

func IsAnalyticsEnabled() bool

IsAnalyticsEnabled will check if analytics is enabled or not and accordingly return the status.

func IsPreDefinedTermFilter

func IsPreDefinedTermFilter(e string) bool

func Recorder

func Recorder() middleware.Middleware

Recorder parses and records the search requests made to elasticsearch along with some other user information in order to calculate and serve useful analytics.

func SetPreferencesInCache

func SetPreferencesInCache(a AnalyticsPreferences)

SetPreferencesInCache will set the analytics preferences in cache.

Types

type ActiveUserSession

type ActiveUserSession struct {
	StartTime int64
	ID        string
	Bounce    bool
	TimeStamp string
}

type ActiveUserSessionES

type ActiveUserSessionES struct {
	ID          string
	UserSession UserSession
}

type ActiveUserSessionItem

type ActiveUserSessionItem struct {
	// contains filtered or unexported fields
}

type ActiveUserSessionTTLMap

type ActiveUserSessionTTLMap struct {
	// contains filtered or unexported fields
}

func InitUserSession

func InitUserSession(ln int, maxTTL int, initialValue *ActiveUserSessionTTLMap) (m *ActiveUserSessionTTLMap)

func (*ActiveUserSessionTTLMap) Delete

func (*ActiveUserSessionTTLMap) Get

func (*ActiveUserSessionTTLMap) Len

func (m *ActiveUserSessionTTLMap) Len() int

func (*ActiveUserSessionTTLMap) Put

type Analytics

type Analytics struct {
	// contains filtered or unexported fields
}

Analytics plugin records and serves basic index or cluster level analytics.

func Instance

func Instance() *Analytics

Instance returns the singleton instace of Analytics plugin. Note: Only this function must be used (both within and outside the package) to obtain the instance analytics in order to avoid stateless instances of the plugin.

func (*Analytics) AlternateRoutes

func (a *Analytics) AlternateRoutes() []plugins.Route

Expose plugin specific routes

func (*Analytics) ESMiddleware

func (a *Analytics) ESMiddleware() []middleware.Middleware

func (*Analytics) InitFunc

func (a *Analytics) InitFunc() error

InitFunc is a part of Plugin interface that gets executed only once, and initializes the dao, i.e. elasticsearch before the plugin is operational.

func (*Analytics) Name

func (a *Analytics) Name() string

Name is a part of Plugin interface that returns the name of the plugin: 'analytics'.

func (*Analytics) RSMiddleware

func (a *Analytics) RSMiddleware() []middleware.Middleware

func (*Analytics) RecordAnalytics

func (a *Analytics) RecordAnalytics(
	request rules.ScriptRequest,
	rsRequestBody *querytranslate.RSQuery,
	response rules.ScriptResponse,
	indices []string,
) (*string, rules.ScriptResponse)

Records the analytics and returns query id and response body with query id

func (*Analytics) RecordClick

func (a *Analytics) RecordClick(r *http.Request, body ClickRecord) rules.ScriptResponse

func (*Analytics) RecordConversion

func (a *Analytics) RecordConversion(r *http.Request, body ConversionRecord) rules.ScriptResponse

func (*Analytics) RecordFavorite

func (a *Analytics) RecordFavorite(req *http.Request, body FavoriteRequest) rules.ScriptResponse

func (*Analytics) RecordSavedSearch

func (a *Analytics) RecordSavedSearch(req *http.Request, body SavedSearchRequest) rules.ScriptResponse

func (*Analytics) Routes

func (a *Analytics) Routes() []plugins.Route

Routes returns the analytics routes that the plugin serves.

type AnalyticsPreferences

type AnalyticsPreferences struct {
	Enable *bool `json:"enable"`
}

func GetPreferencesFromCache

func GetPreferencesFromCache() AnalyticsPreferences

GetPreferencesFromCache will return the analytics preferences from cache.

type ClickRecord

type ClickRecord struct {
	Query     *string         `json:"query"`             // Optional
	QueryID   string          `json:"query_id"`          // Optional
	ClickType ClickType       `json:"click_type"`        // Optional
	ClickOn   *map[string]int `json:"click_on"`          // Required
	UserID    string          `json:"user_id,omitempty"` // Optional
	// TODO: Remove `event_data` in Next major version
	EventData    map[string]interface{}  `json:"event_data,omitempty"`    // Optional
	CustomEvents map[string]interface{}  `json:"custom_events,omitempty"` // Optional
	Meta         *map[string]interface{} `json:"meta"`
}

type ClickSummary

type ClickSummary struct {
	AvgClickPosition float64
	TotalConversions float64
	TotalClicks      float64
}

type ClickType

type ClickType int
const (
	Result ClickType = iota
	Suggestion
)

func (ClickType) MarshalJSON

func (o ClickType) MarshalJSON() ([]byte, error)

MarshalJSON is the implementation of the Marshaler interface for marshaling ClickType type.

func (ClickType) String

func (o ClickType) String() string

String is the implementation of Stringer interface that returns the string representation of ClickType type.

func (*ClickType) UnmarshalJSON

func (o *ClickType) UnmarshalJSON(bytes []byte) error

UnmarshalJSON is the implementation of the Unmarshaler interface for un-marshaling ClickType type.

type ConversionRecord

type ConversionRecord struct {
	QueryID      string                  `json:"query_id"`      // Optional
	ConversionOn *[]string               `json:"conversion_on"` // Required
	Meta         *map[string]interface{} `json:"meta"`
}

type DetailedSummary

type DetailedSummary struct {
	AvgBounceRate               float64 `json:"avg_bounce_rate"`
	AvgUserSessionDuration      float64 `json:"avg_user_session_duration"`
	AvgClickRate                float64 `json:"avg_click_rate"`
	AvgClickPosition            float64 `json:"avg_click_position"`
	AvgResultClickPosition      float64 `json:"avg_results_click_position"`
	AvgSuggestionsClickPosition float64 `json:"avg_suggestions_click_position"`
	AvgSuggestionsClickRate     float64 `json:"avg_suggestions_click_rate"`
	AvgConversionRate           float64 `json:"avg_conversion_rate"`
	TotalResultsCount           float64 `json:"total_results_count"`
	TotalSearches               float64 `json:"total_searches"`
	TotalUsers                  float64 `json:"total_users"`
	TotalUserSessions           float64 `json:"total_user_sessions"`
	TotalBounceUsers            float64 `json:"total_bounce_users"`
	TotalClicks                 float64 `json:"total_clicks"`
	TotalSuggestionsClicks      float64 `json:"total_suggestions_clicks"`
	TotalResultsClicks          float64 `json:"total_results_clicks"`
	TotalConversions            float64 `json:"total_conversions"`
	TotalNoResultsSearches      float64 `json:"total_no_results_searches"`
	NoResultsRate               float64 `json:"no_results_rate"`
	PopularSearches             float64 `json:"popular_searches"`
	AvgClickRatePopularSearches float64 `json:"avg_click_rate_popular_searches"`
	AvgQueryLength              float64 `json:"avg_query_length"`
	InternalServerErrors        float64 `json:"internal_server_errors"`
	BadRequestErrors            float64 `json:"bad_request_errors"`
	HighResponseTimeSearches    float64 `json:"high_response_time_searches"`
}

DetailedSummary represents the detailed summary to extract the insights

type Error

type Error struct {
	// contains filtered or unexported fields
}

type FavoriteES

type FavoriteES struct {
	Id                     *string                 `json:"id,omitempty"`
	QueryId                *string                 `json:"query_id,omitempty"`
	FavoriteOn             *string                 `json:"favorite_on,omitempty"`
	Source                 *string                 `json:"source,omitempty"`
	UserId                 *string                 `json:"user_id,omitempty"`
	CustomEvents           *map[string]interface{} `json:"custom_events,omitempty"`
	CreatedAt              *int64                  `json:"created_at,omitempty"`
	UpdatedAt              *int64                  `json:"updated_at,omitempty"`
	TimeStamp              *string                 `json:"timestamp,omitempty"`
	SearchQuery            *string                 `json:"search_query,omitempty"`
	SearchQueryCharsLength *int                    `json:"search_characters_length,omitempty"`
	Meta                   *map[string]interface{} `json:"meta,omitempty"`
}

type FavoriteRequest

type FavoriteRequest struct {
	Id           *string                 `json:"id,omitempty"`
	QueryId      *string                 `json:"query_id,omitempty"`
	FavoriteOn   *string                 `json:"favorite_on,omitempty"`
	Source       *map[string]interface{} `json:"source,omitempty"`
	UserId       *string                 `json:"user_id,omitempty"`
	CustomEvents *map[string]interface{} `json:"custom_events,omitempty"`
	Meta         *map[string]interface{} `json:"meta,omitempty"`
}

type GetInsight

type GetInsight struct {
	Summary       SummaryRecord
	Insights      []InsightResponseType
	SavedInsights []InsightResponseType
	ReadInsights  []InsightResponseType
}

GetInsight represents the returned shape for getInsights method

type Insight

type Insight struct {
	// Represents the insight title, must be a valid expression
	Title string `json:"title"`
	// Represents the insight description, must be a valid expression
	Description     string           `json:"description"`
	ShortLink       string           `json:"short_link"`
	Recommendations []Recommendation `json:"recommendations"`
	// expression from the `expr` package to evaluate the insight
	Condition string `json:"condition"`
}

Insight represents the insight object

type InsightConfigType

type InsightConfigType struct {
	ID      InsightType `json:"id"`
	Insight Insight     `json:"insight"`
}

InsightConfigType represents the insight object in the config

type InsightEnvironments

type InsightEnvironments struct {
	AvgBounceRate               string
	AvgUserSessionDuration      string
	AvgClickRate                string
	AvgClickPosition            string
	AvgResultClickPosition      string
	AvgSuggestionsClickPosition string
	AvgSuggestionsClickRate     string
	AvgConversionRate           string
	TotalResultsCount           string
	TotalSearches               string
	TotalUsers                  string
	TotalUserSessions           string
	TotalBounceUsers            string
	TotalClicks                 string
	TotalSuggestionsClicks      string
	TotalResultsClicks          string
	TotalConversions            string
	TotalNoResultsSearches      string
	NoResultsRate               string
	PopularSearches             string
	AvgClickRatePopularSearches string
	AvgQueryLength              string
	InternalServerErrors        string
	BadRequestErrors            string
	HighResponseTimeSearches    string
	ToFloat                     func(string) float64
	ToString                    func(float64, int) string
	FormatNumber                func(float64) string
}

InsightEnvironments represents the environment variables for Insight Title

type InsightReportAnalytics

type InsightReportAnalytics struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	Link        string `json:"link"`
}

InsightReportAnalytics represents the insight object

type InsightResponse

type InsightResponse struct {
	/* Represents the recommendation title, for an example: "There are {value} no result searches".
	{value} is a variable which will be replaced by the actual value
	*/
	Title           string           `json:"title"`
	Description     string           `json:"description"`
	Recommendations []Recommendation `json:"recommendations"`
	ShortLink       string           `json:"short_link"`
}

InsightResponse represents the insight response object

type InsightResponseType

type InsightResponseType struct {
	ID      InsightType     `json:"id"`
	Insight InsightResponse `json:"insight"`
}

InsightResponseType represents the insight endpoint response

type InsightStatus

type InsightStatus int

InsightStatus represents the type of the insight status

const (
	// Saved represents the saved status for insight
	Saved InsightStatus = iota
	// Read represents the read status for insight
	Read
	// Deleted represents the deleted status for insight
	Deleted
)

func (InsightStatus) MarshalJSON

func (o InsightStatus) MarshalJSON() ([]byte, error)

MarshalJSON is the implementation of the Marshaler interface for marshaling InsightStatus type.

func (InsightStatus) String

func (o InsightStatus) String() string

String is the implementation of Stringer interface that returns the string representation of InsightStatus type.

func (*InsightStatus) UnmarshalJSON

func (o *InsightStatus) UnmarshalJSON(bytes []byte) error

UnmarshalJSON is the implementation of the Unmarshaler interface for un-marshaling InsightStatus type.

type InsightStatusEsDoc

type InsightStatusEsDoc struct {
	Saved   []InsightType `json:"saved"`
	Read    []InsightType `json:"read"`
	Deleted []InsightType `json:"deleted"`
}

InsightStatusEsDoc represents the ES doc for insight status

type InsightStatusRequest

type InsightStatusRequest struct {
	ID     *InsightType  `json:"id"`
	Status InsightStatus `json:"status"`
}

InsightStatusRequest represents the request body to update the status

type InsightType

type InsightType int

InsightType represents the type of the insight

const (
	// NoResults represents the no_results property in insight
	NoResults InsightType = iota
	// LowClicks represents the low_clicks property in insight
	LowClicks
	// LowSuggestionsClicks represents the `low_suggestions_clicks` property in insight
	LowSuggestionsClicks
	// AvgClickPosition represents the avg_click_position property in insight
	AvgClickPosition
	// PopularSearches represents the popular_searches property in insight
	PopularSearches
	// PopularSearchesWithLowClicks represents the popular_searches_with_low_clicks property in insight
	PopularSearchesWithLowClicks
	// LongTailSearches represents the long_tail_searches property in insight
	LongTailSearches
	// BounceRate represents the bounce_rate property in insight
	BounceRate
	// HighResponseTime represents the high_response_time property in insight
	HighResponseTime
	// Error500 represents the error_500 property in insight
	Error500
	// Error400 represents the error_400 property in insight
	Error400
)

func (InsightType) MarshalJSON

func (o InsightType) MarshalJSON() ([]byte, error)

MarshalJSON is the implementation of the Marshaler interface for marshaling InsightType type.

func (InsightType) String

func (o InsightType) String() string

String is the implementation of Stringer interface that returns the string representation of InsightType type.

func (*InsightType) UnmarshalJSON

func (o *InsightType) UnmarshalJSON(bytes []byte) error

UnmarshalJSON is the implementation of the Unmarshaler interface for un-marshaling InsightType type.

type InsightsEnvironments

type InsightsEnvironments struct {
	DateRange        string                   `json:"date_range"` // format Apr 1 - Apr 30
	NumberOfInsights int                      `json:"number_of_insights"`
	Insights         []InsightReportAnalytics `json:"insights"`
}

InsightsEnvironments represents the insights environment variables available for mail template for analytics

type Link struct {
	ShortLink string
	LongLink  string
}

Link represents a link

type Links struct {
	Language          Link
	Rules             Link
	SearchSettings    Link
	Synonyms          Link
	QuerySuggestions  Link
	ResultSettings    Link
	IndexSettings     Link
	RequestLogs       Link
	NoResultsSearches Link
	PopularSearches   Link
}

Links represents all link

type Location

type Location struct {
	Country     string
	City        string
	Coordinates string
}

type MappingsMigration

type MappingsMigration struct {
	NewMapping string
	// contains filtered or unexported fields
}

func (MappingsMigration) ConditionCheck

func (m MappingsMigration) ConditionCheck() (bool, *util.Error)

func (MappingsMigration) IsAsync

func (m MappingsMigration) IsAsync() bool

func (MappingsMigration) Script

func (m MappingsMigration) Script() *util.Error

type QueryFilter

type QueryFilter struct {
	Type       string // Valid types are `exists` => We can add new types as per need
	Field      string
	NestedPath string
}

TODO: we can use enums for query types

type QueryParams

type QueryParams struct {
	From     string
	To       string
	Size     int
	Timezone string
}

func RangeQueryParams

func RangeQueryParams(values url.Values) QueryParams

RangeQueryParams exposes the rangeQueryParams method to make it accessible in the whole package.

type RecentDocument

type RecentDocument struct {
	DocumentId *string                 `json:"document_id"`
	Source     *map[string]interface{} `json:"source"`
	Users      *map[string]int64       `json:"users"`
	Index      *string                 `json:"index"`
}

RecentDocument will contain details about the recent document viewed by an user.

func (*RecentDocument) ToPublic

func (r *RecentDocument) ToPublic(userId string) RecentDocumentPublic

ToPublic will convert the internal values into a public structure

type RecentDocumentPublic

type RecentDocumentPublic struct {
	DocumentId   *string                 `json:"document_id"`
	UserId       *string                 `json:"user_id"`
	Index        *string                 `json:"index"`
	Source       *map[string]interface{} `json:"source"`
	LastAccessed *int64                  `json:"last_accessed,omitempty"`
}

RecentDocumentPublic will be the visible recent document that the API will accept and return

func (*RecentDocumentPublic) ToInternal

func (r *RecentDocumentPublic) ToInternal() RecentDocument

ToInternal will convert the public document to internal document.

This function will not validate the values to make sure that they are present.

This function will only be used if the document doesn't already exist in the index. If it already exists, we will do an `_update_by_query` with a script to inject the `user_id` in the `users` map.

type Recommendation

type Recommendation struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	// Represents the short link for e.g '/cluster/no-results-searches'
	ShortLink string `json:"short_link"`
	// Represents the full link for e.g 'https://dash.reactivesearch.io/cluster/no-results-searches'
	LongLink string `json:"long_link"`
}

Recommendation represents the structure of the insight recommendation

type RecordUserSessionConfig

type RecordUserSessionConfig struct {
	// contains filtered or unexported fields
}

type ReportAnalyticsRequest

type ReportAnalyticsRequest struct {
	Summary             SummaryRecord        `json:"summary"`
	SummaryComparison   SummaryComparison    `json:"summary_comparison"`
	Insights            InsightsEnvironments `json:"insights"`
	Users               []string             `json:"users"`
	FeatureCustomEvents bool                 `json:"feature_custom_events"`
}

ReportAnalyticsRequest represents the request body for report analytics

type RequestHIT

type RequestHIT struct {
	ID    string `json:"id"`
	Index string `json:"index"`
}

type SavedSearchES

type SavedSearchES struct {
	QueryId                *string                 `json:"query_id,omitempty"`
	SavedSearchId          *string                 `json:"save_search_id,omitempty"`
	SavedSearchName        *string                 `json:"save_search_name,omitempty"`
	SavedSearchMeta        *map[string]interface{} `json:"save_search_meta,omitempty"`
	UserId                 *string                 `json:"user_id,omitempty"`
	CustomEvents           *map[string]interface{} `json:"custom_events,omitempty"`
	SearchState            querytranslate.Endpoint `json:"search_state,omitempty"`
	CreatedAt              *int64                  `json:"created_at,omitempty"`
	UpdatedAt              *int64                  `json:"updated_at,omitempty"`
	TimeStamp              *string                 `json:"timestamp,omitempty"`
	SearchQuery            *string                 `json:"search_query,omitempty"`
	SearchQueryCharsLength *int                    `json:"search_characters_length,omitempty"`
}

type SavedSearchRequest

type SavedSearchRequest struct {
	QueryId         *string                 `json:"query_id,omitempty"`
	SavedSearchId   *string                 `json:"save_search_id,omitempty"`
	SavedSearchName *string                 `json:"save_search_name,omitempty"`
	SavedSearchMeta *map[string]interface{} `json:"save_search_meta,omitempty"`
	UserId          *string                 `json:"user_id,omitempty"`
	CustomEvents    *map[string]interface{} `json:"custom_events,omitempty"`
}

type SavedSearchesFilters

type SavedSearchesFilters struct {
	FromTimeStamp string
	ToTimeStamp   string
	TimeZone      string
	Size          int
	MinChars      *int
	CustomEvents  map[string]interface{}
}

type SearchRecord

type SearchRecord struct {
	Query       *string            `json:"query"`                 // Required
	QueryID     string             `json:"query_id"`              // Optional
	Filters     *map[string]string `json:"filters,omitempty"`     // Optional
	Impressions *[]RequestHIT      `json:"impressions,omitempty"` // Optional
	TotalHits   *int64             `json:"total_hits,omitempty"`  // Optional
	UserID      string             `json:"user_id,omitempty"`     // Optional
	// TODO: Remove `event_data` in Next major version
	EventData    map[string]interface{}  `json:"event_data,omitempty"`    // Optional
	CustomEvents map[string]interface{}  `json:"custom_events,omitempty"` // Optional
	Meta         *map[string]interface{} `json:"meta"`
}

type SummaryComparison

type SummaryComparison struct {
	AvgBounceRateComparison               float64 `json:"avg_bounce_rate_sc"`
	AvgBounceRatePrevious                 float64 `json:"avg_bounce_rate_prev"`
	AvgUserSessionDurationComparison      float64 `json:"avg_user_session_duration_sc"`
	AvgUserSessionDurationPrevious        float64 `json:"avg_user_session_duration_prev"`
	AvgClickRateComparison                float64 `json:"avg_click_rate_sc"`
	AvgClickRatePrevious                  float64 `json:"avg_click_rate_prev"`
	AvgClickPositionComparison            float64 `json:"avg_click_position_sc"`
	AvgClickPositionPrevious              float64 `json:"avg_click_position_prev"`
	AvgResultClickPositionComparison      float64 `json:"avg_results_click_position_sc"`
	AvgResultClickPositionPrevious        float64 `json:"avg_results_click_position_prev"`
	AvgSuggestionsClickPositionComparison float64 `json:"avg_suggestions_click_position_sc"`
	AvgSuggestionsClickPositionPrevious   float64 `json:"avg_suggestions_click_position_prev"`
	AvgSuggestionsClickRateComparison     float64 `json:"avg_suggestions_click_rate_sc"`
	AvgSuggestionsClickRatePrevious       float64 `json:"avg_suggestions_click_rate_prev"`
	AvgConversionRateComparison           float64 `json:"avg_conversion_rate_sc"`
	AvgConversionRatePrevious             float64 `json:"avg_conversion_rate_prev"`
	TotalResultsCountComparison           float64 `json:"total_results_count_sc"`
	TotalResultsCountPrevious             float64 `json:"total_results_count_prev"`
	TotalSearchesComparison               float64 `json:"total_searches_sc"`
	TotalSearchesPrevious                 float64 `json:"total_searches_prev"`
	TotalUsersComparison                  float64 `json:"total_users_sc"`
	TotalUsersPrevious                    float64 `json:"total_users_prev"`
	TotalUserSessionsComparison           float64 `json:"total_user_sessions_sc"`
	TotalUserSessionsPrevious             float64 `json:"total_user_sessions_prev"`
	TotalBounceUsersComparison            float64 `json:"total_bounce_users_sc"`
	TotalBounceUsersPrevious              float64 `json:"total_bounce_users_prev"`
	TotalClicksComparison                 float64 `json:"total_clicks_sc"`
	TotalClicksPrevious                   float64 `json:"total_clicks_prev"`
	TotalSuggestionsClicksComparison      float64 `json:"total_suggestions_clicks_sc"`
	TotalSuggestionsClicksPrevious        float64 `json:"total_suggestions_clicks_prev"`
	TotalResultsClicksComparison          float64 `json:"total_results_clicks_sc"`
	TotalResultsClicksPrevious            float64 `json:"total_results_clicks_prev"`
	TotalConversionsComparison            float64 `json:"total_conversions_sc"`
	TotalConversionsPrevious              float64 `json:"total_conversions_prev"`
	TotalNoResultsSearchesComparison      float64 `json:"total_no_results_searches_sc"`
	TotalNoResultsSearchesPrevious        float64 `json:"total_no_results_searches_prev"`
	NoResultsRateComparison               float64 `json:"no_results_rate_sc"`
	NoResultsRatePrevious                 float64 `json:"no_results_rate_prev"`
}

SummaryComparison represents the analytics summary comparison environment variables available for mail template for analytics

type SummaryRecord

type SummaryRecord struct {
	AvgBounceRate               float64 `json:"avg_bounce_rate"`
	AvgUserSessionDuration      float64 `json:"avg_user_session_duration"`
	AvgClickRate                float64 `json:"avg_click_rate"`
	AvgClickPosition            float64 `json:"avg_click_position"`
	AvgResultClickPosition      float64 `json:"avg_results_click_position"`
	AvgSuggestionsClickPosition float64 `json:"avg_suggestions_click_position"`
	AvgSuggestionsClickRate     float64 `json:"avg_suggestions_click_rate"`
	AvgConversionRate           float64 `json:"avg_conversion_rate"`
	TotalResultsCount           float64 `json:"total_results_count"`
	TotalSearches               float64 `json:"total_searches"`
	TotalUsers                  float64 `json:"total_users"`
	TotalUserSessions           float64 `json:"total_user_sessions"`
	TotalBounceUsers            float64 `json:"total_bounce_users"`
	TotalClicks                 float64 `json:"total_clicks"`
	TotalSuggestionsClicks      float64 `json:"total_suggestions_clicks"`
	TotalResultsClicks          float64 `json:"total_results_clicks"`
	TotalConversions            float64 `json:"total_conversions"`
	TotalNoResultsSearches      float64 `json:"total_no_results_searches"`
	NoResultsRate               float64 `json:"no_results_rate"`
}

SummaryRecord represents the summary record

type SummaryResponse

type SummaryResponse struct {
	Summary          SummaryRecord  `json:"summary"`
	CompateTimeframe *SummaryRecord `json:"compare_timeframe,omitempty"`
}

SummaryResponse represents the summary endpoint response struct

type TTLMap

type TTLMap struct {
	// contains filtered or unexported fields
}

func InitSession

func InitSession(ln int, maxTTL int) (m *TTLMap)

func (*TTLMap) DeleteStaleSessions

func (m *TTLMap) DeleteStaleSessions(whitelisted []string, userID string)

TODO: Running a loop on active sessions is not performant It happens synchronously so it would affect the search latency

func (*TTLMap) Get

func (m *TTLMap) Get(k string) (v string)

func (*TTLMap) Len

func (m *TTLMap) Len() int

func (*TTLMap) Put

func (m *TTLMap) Put(k, v string)

type TTLMapTimestamp

type TTLMapTimestamp struct {
	// contains filtered or unexported fields
}

func InitTimestampSession

func InitTimestampSession(ln int, maxTTL int) (m *TTLMapTimestamp)

func (*TTLMapTimestamp) Get

func (m *TTLMapTimestamp) Get(k string) (v int64)

func (*TTLMapTimestamp) Len

func (m *TTLMapTimestamp) Len() int

func (*TTLMapTimestamp) Put

func (m *TTLMapTimestamp) Put(k string, v int64)

type UpdateConfig

type UpdateConfig struct {
	DocID        string
	Script       string
	Record       map[string]interface{}
	ScriptParams map[string]interface{}
}

type User

type User struct {
	Email string `json:"email"`
}

type UserSession

type UserSession struct {
	StartTime           *int64    `json:"start_time,omitempty"`
	LastInteractionTime *int64    `json:"last_interaction_time,omitempty"`
	Duration            *int64    `json:"duration,omitempty"`
	UserID              *string   `json:"user_id,omitempty"`
	Indices             *[]string `json:"indices,omitempty"`
	Bounce              *bool     `json:"bounce,omitempty"`
	TimeStamp           string    `json:"timestamp,omitempty"`
	IP                  *string   `json:"ip,omitempty"`
}

UserSession represents the user session record in the Elasticsearch

type UserSessionMappingsMigration

type UserSessionMappingsMigration struct {
	NewMapping string
	// contains filtered or unexported fields
}

func (UserSessionMappingsMigration) ConditionCheck

func (u UserSessionMappingsMigration) ConditionCheck() (bool, *util.Error)

func (UserSessionMappingsMigration) IsAsync

func (m UserSessionMappingsMigration) IsAsync() bool

func (UserSessionMappingsMigration) Script

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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