Skip to content

chore: add user actions preview option #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/src/client/faro/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function initializeFaro(): Faro {
itemLimit: 100,
},

trackUserActions: true,
trackUserActionsPreview: true,
});

faro.api.pushLog(['Faro was initialized']);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ export interface Config<P = APIEvent> {
* This is a preview feature.
* We have tested it thoroughly, but it is possible that it might not work as expected in all cases.
*/
trackUserActions?: boolean;
// TODO: remove preview postfix when feature is ga
trackUserActionsPreview?: boolean;

/**
* Configure your own attribute name for tracking user actions. Default is 'data-faro-user-action-name'
Expand Down
53 changes: 27 additions & 26 deletions packages/web-sdk/src/config/makeCoreConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defaultLogArgsSerializer, isFunction } from '@grafana/faro-core';
import type { LogArgsSerializer } from '@grafana/faro-core';

import { userActionDataAttribute } from '../instrumentations/userActions';

import { makeCoreConfig } from './makeCoreConfig';

describe('defaultMetas', () => {
Expand Down Expand Up @@ -156,30 +158,29 @@ describe('config', () => {
expect(config?.sessionTracking?.session).toStrictEqual(sessionMeta);
});

// TODO: re-add tests on beta release
// it('trackUserActions settings defaults are applied', () => {
// const browserConfig = {
// url: 'http://example.com/my-collector',
// app: {},gca
// };
// const config = makeCoreConfig(browserConfig);

// expect(config).toBeTruthy();
// expect(config?.trackUserActions).toBe(false);
// expect(config?.trackUserActionsDataAttributeName).toBe(userActionDataAttribute);
// });

// it('trackUserActions setting are added to the config as provided by the user', () => {
// const browserConfig = {
// url: 'http://example.com/my-collector',
// app: {},
// trackUserActions: true,
// trackUserActionsDataAttributeName: 'data-test-action-name',
// };
// const config = makeCoreConfig(browserConfig);

// expect(config).toBeTruthy();
// expect(config?.trackUserActions).toBe(true);
// expect(config?.trackUserActionsDataAttributeName).toBe('data-test-action-name');
// });
it('trackUserActions settings defaults are applied', () => {
const browserConfig = {
url: 'http://example.com/my-collector',
app: {},
};
const config = makeCoreConfig(browserConfig);

expect(config).toBeTruthy();
expect(config?.trackUserActionsPreview).toBe(false);
expect(config?.trackUserActionsDataAttributeName).toBe(userActionDataAttribute);
});

it('trackUserActions setting are added to the config as provided by the user', () => {
const browserConfig = {
url: 'http://example.com/my-collector',
app: {},
trackUserActionsPreview: true,
trackUserActionsDataAttributeName: 'data-test-action-name',
};
const config = makeCoreConfig(browserConfig);

expect(config).toBeTruthy();
expect(config?.trackUserActionsPreview).toBe(true);
expect(config?.trackUserActionsDataAttributeName).toBe('data-test-action-name');
});
});
10 changes: 4 additions & 6 deletions packages/web-sdk/src/config/makeCoreConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export function makeCoreConfig(browserConfig: BrowserConfig): Config {
preventGlobalExposure = false,
unpatchedConsole = defaultUnpatchedConsole,
webVitalsInstrumentation,
// TODO: enable on official preview release
// trackUserActions = false,
trackUserActionsPreview = false,
trackUserActionsDataAttributeName = userActionDataAttribute,
trackUserActionsExcludeItem,
}: BrowserConfig = browserConfig;
Expand Down Expand Up @@ -110,19 +109,18 @@ export function makeCoreConfig(browserConfig: BrowserConfig): Config {
trackWebVitalsAttribution,
consoleInstrumentation,
webVitalsInstrumentation,
// TODO: enable on official preview release (remove the "false" value)
trackUserActions: false,
trackUserActionsPreview,
trackUserActionsDataAttributeName,
trackUserActionsExcludeItem,
};
}

function getFilteredInstrumentations(
instrumentations: Instrumentation[],
{ trackUserActions }: BrowserConfig
{ trackUserActionsPreview }: BrowserConfig
): Instrumentation[] {
return instrumentations.filter((instr) => {
if (instr.name === '@grafana/faro-web-sdk:instrumentation-user-action' && !trackUserActions) {
if (instr.name === '@grafana/faro-web-sdk:instrumentation-user-action' && !trackUserActionsPreview) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe('Resource observer', () => {
const mockPushEvent = jest.fn();
jest.spyOn(urlUtilsModule, 'isUrlIgnored').mockReturnValueOnce(false);

const trackUserActionsConfig = mockConfig({ trackUserActions: true });
const trackUserActionsConfig = mockConfig({ trackUserActionsPreview: true });
initializeFaro(trackUserActionsConfig);

observeResourceTimings(mockNavigationId, mockPushEvent, mockObservable);
Expand All @@ -181,7 +181,7 @@ describe('Resource observer', () => {
const mockPushEvent = jest.fn();
jest.spyOn(urlUtilsModule, 'isUrlIgnored').mockReturnValueOnce(false);

const trackUserActionsConfig = mockConfig({ trackUserActions: false });
const trackUserActionsConfig = mockConfig({ trackUserActionsPreview: false });
initializeFaro(trackUserActionsConfig);

observeResourceTimings(mockNavigationId, mockPushEvent, mockObservable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function observeResourceTimings(
faroResourceId: genShortID(),
};

if (faro.config.trackUserActions) {
if (faro.config.trackUserActionsPreview) {
observable?.notify({
type: RESOURCE_ENTRY,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('UserActionsInstrumentation', () => {
makeCoreConfig(
mockConfig({
trackUserActionsDataAttributeName: userActionDataAttribute,
trackUserActions: true,
trackUserActionsPreview: true,
})
)
);
Expand Down