Class: Session
Hierarchy
SessionEvents
↳
Session
Constructors
constructor
• new Session(args
, req?
)
Parameters
Name | Type |
---|---|
args | SessionArgs |
req? | IncomingMessage |
Overrides
SessionEvents.constructor
Properties
lastKeepAlive
▪ Static
lastKeepAlive: number
= 0
Accessors
activeVariants
• get
activeVariants(): ActiveVariant
[]
The currently active experiment variants. This is intended for reporting information to other systems. It should not be used as an input for any display or logic on your site.
These are updated after a call to requestImpression, useImpression or useFeature The active variants will not be available until after the first call to one of these methods
Returns
constructedNewCache
• get
constructedNewCache(): boolean
Returns true if the call to session constructor [i.e. new Session()] created a new cache This is true iff
- this is the first time creating a session
- the previous session expired
- the session was created with different session args then what was cached
- you are using an ephemeral cache (e.g. in SSR)
This call is useful in the browser to determine if you've created a new session
Returns
boolean
requestedFeatures
• get
requestedFeatures(): RequestedFeature
[]
All the features that have been requested so far. This is intended for reporting information to other systems. It should not be used as an input for any display or logic on your site.
Returns
Methods
addIncomingMessageArgs
▸ addIncomingMessageArgs(incomingMessage
): void
Add implicit session arguments (such as the ip address) from the incoming message
Parameters
Name | Type | Description |
---|---|---|
incomingMessage | IncomingMessage | an HTTP IncomingMessage |
Returns
void
args
▸ args(): SessionArgs
Returns
clearImpressionStats
▸ clearImpressionStats(): void
Clear all impression stats. Resets cache hits, misses, and noops
Returns
void
commSnapshot
▸ commSnapshot(): CommSnapshot
Returns information about this sessions communication with the impression server
Returns
getImpressionStats
▸ getImpressionStats(): Object
Get impression stats
Returns
Object
returns features that have were served from cache (hits), not served from cache (misses), or not requested (noOps)
Name | Type |
---|---|
cacheHits | string [] |
cacheMisses | string [] |
cacheNoOps | string [] |
loadingImpressions | number |
keepAlive
▸ keepAlive(): boolean
Mark the session as still active
Returns
boolean
requestCacheFill
▸ requestCacheFill<Q
>(query
): Promise
<void
>
Async function to fill the cache with impressions. This is typically used for SSR. This function will first test the cache to see if the requested impressions are already cached. If not it will fetch the impression and populate the cache. The cached impressions will not be logged and will not count towards any metrics until they are fetched from the cache by Session.requestImpression or useImpression
Typeparam
Type information for the request and returned impression. Typically inferred from the query.
Type parameters
Name | Type |
---|---|
Q | extends Query <"ExampleFeature" | "ExampleFeature2" , Q > |
Parameters
Name | Type | Description |
---|---|---|
query | Q | Features to request and their arguments. |
Returns
Promise
<void
>
A promise that will resolve with the impression and the current set of feature flags. On an error, it will return the default values for the impression and flags, as well as an additional informational error value.
requestImpression
▸ requestImpression<Q
>(query
, impressionId?
): Promise
<{ error?
: ErrorTypes
; flags
: FlagsType
<Q
> ; impression
: ImpressionType
<Q
> }>
Async function to get the impression and on/off flags associated with a feature.
Typeparam
Type information for the request and returned impression. Typically inferred from the query.
Type parameters
Name | Type |
---|---|
Q | extends Query <"ExampleFeature" | "ExampleFeature2" , Q > |
Parameters
Name | Type | Description |
---|---|---|
query | Q | Features to request and their arguments. |
impressionId? | string | The impression id. |
Returns
Promise
<{ error?
: ErrorTypes
; flags
: FlagsType
<Q
> ; impression
: ImpressionType
<Q
> }>
A promise that will resolve with the impression and the current set of feature flags. On an error, it will return the default values for the impression and flags, as well as an additional informational error value.
toJSON
▸ toJSON(): SessionJSON
Serializes a session to JSON. Used in conjunction with useSessionJSON. Useful to transfer a session for SSR.
Returns
the serialized JSON
fromDeviceId
▸ Static
fromDeviceId(deviceId
, req?
): Session
Parameters
Name | Type |
---|---|
deviceId | string |
req? | IncomingMessage |