Skip to main content

# Analytics

Analytics scripting object

## Extends​

- `ScriptingObject`

## Implements​

- `IAnalytics`

## Accessors​

### id​

#### Get Signature​

    get id(): string;

get unique id of the scripting object

##### Returns​

`string`

#### Implementation of​

    IAnalytics.id

#### Inherited from​

    ScriptingObject.id

### objectType​

#### Get Signature​

    get objectType(): string;

get type of the scripting object

##### Returns​

`string`

#### Implementation of​

    IAnalytics.objectType

#### Inherited from​

    ScriptingObject.objectType

## Constructors​

### Constructor​

    new Analytics(params: AnalyticsParams): Analytics;

Creates new instance of Analytics scripting object

#### Parameters​

##### params​

`AnalyticsParams`

Analytics constructor parameters

#### Returns​

`Analytics`

#### Overrides​

    ScriptingObject.constructor

## Properties​

### _dispose()​

    _dispose: () => void;

dispose the scripting object

#### Returns​

`void`

#### Implementation of​

    IAnalytics._dispose

#### Inherited from​

    ScriptingObject._dispose

### _toJSON()​

    _toJSON: () => RemotingScriptingObject;

transform the scripting object to a format suitable for transmitting over window.postMessage

#### Returns​

`RemotingScriptingObject`

marshalled scripting object

#### Implementation of​

    IAnalytics._toJSON

#### Inherited from​

    ScriptingObject._toJSON

### deleteTimingEventSamplingRatio()​

    deleteTimingEventSamplingRatio: (names: string[]) => void;

Remove sampling configuration for timing events Falls back to default sampling ratio (0.25)

#### Parameters​

##### names​

`string`[]

array of timing event names

#### Returns​

`void`

#### Example​

    analytics.deleteTimingEventSamplingRatio(['api-call', 'user-interaction']);

#### Implementation of​

    IAnalytics.deleteTimingEventSamplingRatio

### dispose()​

    dispose: () => void;

dispose the scripting object

#### Returns​

`void`

#### Inherited from​

    ScriptingObject.dispose

### endTiming()​

    endTiming: (start: string | PerfMark, options: TimingOptions) => Promise<void>;

end timing measure

#### Parameters​

##### start​

name used to start timing measure or return value of the startTiming method

`string` | `PerfMark`

##### options​

`TimingOptions`

additional details related to the measurement

#### Returns​

`Promise`<`void`>

a promise that resolves when the timing measurement is ended

#### Example​

    const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
    // do some work
    await analytics.endTiming(longTaskMeasurement, { appId: 'myApp', appUrl: 'https://myapp.com' });

    const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
    // do some work
    await analytics.endTiming('LongTask', { appId: 'loanApp', appUrl: 'https://loanApp.com' });

#### Implementation of​

    IAnalytics.endTiming

### getAllTimingEventSamplingRatios()​

    getAllTimingEventSamplingRatios: () => Record<string, number>;

Get all configured timing event sampling ratios

#### Returns​

`Record`<`string`, `number`>

object with timing event names and their sampling ratios

#### Example​

    const ratios = analytics.getAllTimingEventSamplingRatios();
    console.log(ratios); // { 'api-call': 0.1, 'user-interaction': 0.5 }

#### Implementation of​

    IAnalytics.getAllTimingEventSamplingRatios

### getTimingEventSamplingRatio()​

    getTimingEventSamplingRatio: (names: string[]) => Record<string, number | undefined>;

Get sampling ratios for timing events

#### Parameters​

##### names​

`string`[]

array of timing event names

#### Returns​

`Record`<`string`, `number` | `undefined`>

object with ratios for each event (undefined if using default)

#### Example​

    const ratios = analytics.getTimingEventSamplingRatio(['api-call', 'user-interaction']);
    console.log(ratios); // { 'api-call': 0.1, 'user-interaction': 0.5 }

#### Implementation of​

    IAnalytics.getTimingEventSamplingRatio

### sendBAEvent()​

    sendBAEvent: (eve: BAEvent) => Promise<void>;

send business analytics event

#### Parameters​

##### eve​

`BAEvent`

business analytics event data

#### Returns​

`Promise`<`void`>

promise that resolves when the event is sent

#### Implementation of​

    IAnalytics.sendBAEvent

### setTimingEventSamplingRatio()​

    setTimingEventSamplingRatio: (ratios: Record<string, number>) => void;

Set sampling ratios for timing events

#### Parameters​

##### ratios​

`Record`<`string`, `number`>

object with timing event names and their sampling ratios (0 to 1)

#### Returns​

`void`

#### Example​

    analytics.setTimingEventSamplingRatio({
      'api-call': 0.1,
      'user-interaction': 0.5,
      'page-load': 0.8
    });

#### Implementation of​

    IAnalytics.setTimingEventSamplingRatio

### startTiming()​

    startTiming: (name: string, options: TimingOptions) => Promise<{
      name: string;
      startTime: number;
    }>;

start timing measure

#### Parameters​

##### name​

`string`

unique name for the timing measurement. If a measurement with the same name is already running, it will be replaced

##### options​

`TimingOptions`

additional details related to the measurement

#### Returns​

`Promise`<{ `name`: `string`; `startTime`: `number`; }>

a promise that resolves to a PerformanceMeasure object

#### Implementation of​

    IAnalytics.startTiming