fix(frontend-plugin-api): default api config error
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
+22
-4
@@ -493,8 +493,8 @@ describe('GoogleAnalytics4', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Backward compatibility', () => {
|
||||
it('fallback category for legacy context extension property', () => {
|
||||
describe('api backward compatibility', () => {
|
||||
it('continue working with legacy App category', () => {
|
||||
const api = GoogleAnalytics4.fromConfig(basicValidConfig);
|
||||
|
||||
expect(api.captureEvent).toBeDefined();
|
||||
@@ -512,6 +512,24 @@ describe('GoogleAnalytics4', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('use lowercase app as the new default category', () => {
|
||||
const api = GoogleAnalytics4.fromConfig(basicValidConfig);
|
||||
|
||||
expect(api.captureEvent).toBeDefined();
|
||||
|
||||
api.captureEvent({
|
||||
action: 'navigate',
|
||||
subject: '/',
|
||||
context: { ...context, extensionId: '', extension: '' },
|
||||
});
|
||||
|
||||
expect(fnEvent).toHaveBeenCalledWith('page_view', {
|
||||
action: 'page_view',
|
||||
label: '/',
|
||||
category: 'app',
|
||||
});
|
||||
});
|
||||
|
||||
it('prioritize new context extension id over old extension property', () => {
|
||||
const api = GoogleAnalytics4.fromConfig(basicValidConfig);
|
||||
|
||||
@@ -520,13 +538,13 @@ describe('GoogleAnalytics4', () => {
|
||||
api.captureEvent({
|
||||
action: 'navigate',
|
||||
subject: '/',
|
||||
context: { ...context, extensionId: 'App', extension: '' },
|
||||
context: { ...context, extensionId: 'app', extension: '' },
|
||||
});
|
||||
|
||||
expect(fnEvent).toHaveBeenCalledWith('page_view', {
|
||||
action: 'page_view',
|
||||
label: '/',
|
||||
category: 'App',
|
||||
category: 'app',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+3
-2
@@ -171,9 +171,10 @@ export class GoogleAnalytics4 implements AnalyticsApi, NewAnalyticsApi {
|
||||
}
|
||||
|
||||
const extensionId = context.extensionId || context.extension;
|
||||
const category = extensionId ? String(extensionId) : 'App';
|
||||
const category = extensionId ? String(extensionId) : 'app';
|
||||
|
||||
if (action === 'navigate' && category === 'App') {
|
||||
// The legacy default extension was 'App' and the new one is 'app'
|
||||
if (action === 'navigate' && category.toLocaleLowerCase() === 'app') {
|
||||
this.capture.event(
|
||||
{
|
||||
category,
|
||||
|
||||
Reference in New Issue
Block a user