@optimizely/optimizely-sdk
Version:
JavaScript SDK for Optimizely Feature Experimentation, Optimizely Full Stack (legacy), and Optimizely Rollouts
109 lines (108 loc) • 3.46 kB
TypeScript
/**
* Copyright 2022, 2024, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DecisionObj } from '../../core/decision_service';
import { ProjectConfig, Region } from '../../project_config/project_config';
import { EventTags, UserAttributes } from '../../shared_types';
import { LoggerFacade } from '../../logging/logger';
import { Platform } from '../../platform_support';
export type VisitorAttribute = {
entityId: string;
key: string;
value: string | number | boolean;
};
type EventContext = {
region?: Region;
accountId: string;
projectId: string;
revision: string;
clientName: string;
clientVersion: string;
anonymizeIP: boolean;
botFiltering?: boolean;
};
type EventType = 'impression' | 'conversion';
export type BaseUserEvent<T extends EventType> = {
type: T;
timestamp: number;
uuid: string;
context: EventContext;
user: {
id: string;
attributes: VisitorAttribute[];
};
};
export type ImpressionEvent = BaseUserEvent<'impression'> & {
layer: {
id: string | null;
} | null;
experiment: {
id: string | null;
key: string;
} | null;
variation: {
id: string | null;
key: string;
} | null;
ruleKey: string;
flagKey: string;
ruleType: string;
enabled: boolean;
cmabUuid?: string;
};
export type ConversionEvent = BaseUserEvent<'conversion'> & {
event: {
id: string | null;
key: string;
};
revenue: number | null;
value: number | null;
tags?: EventTags;
};
export type UserEvent = ImpressionEvent | ConversionEvent;
export declare const areEventContextsEqual: (eventA: UserEvent, eventB: UserEvent) => boolean;
export type ImpressionConfig = {
decisionObj: DecisionObj;
userId: string;
flagKey: string;
enabled: boolean;
userAttributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
};
/**
* Creates an ImpressionEvent object from decision data
* @param {ImpressionConfig} config
* @return {ImpressionEvent} an ImpressionEvent object
*/
export declare const buildImpressionEvent: ({ configObj, decisionObj, userId, flagKey, enabled, userAttributes, clientEngine, clientVersion, }: ImpressionConfig) => ImpressionEvent;
export type ConversionConfig = {
eventKey: string;
eventTags?: EventTags;
userId: string;
userAttributes?: UserAttributes;
clientEngine: string;
clientVersion: string;
configObj: ProjectConfig;
};
/**
* Creates a ConversionEvent object from track
* @param {ConversionConfig} config
* @return {ConversionEvent} a ConversionEvent object
*/
export declare const buildConversionEvent: ({ configObj, userId, userAttributes, clientEngine, clientVersion, eventKey, eventTags, }: ConversionConfig, logger?: LoggerFacade) => ConversionEvent;
export declare const __platforms: Platform[];
export {};