Skip to content

Commit

Permalink
Merge pull request #17491 from mozilla/FXA-10317-v2
Browse files Browse the repository at this point in the history
fix(glean): Fix ProductPromo firing extra view event, add glean click event
  • Loading branch information
LZoog authored Aug 28, 2024
2 parents d0cd5bd + 3486c83 commit bd68ab7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import React from 'react';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import ProductPromo from '.';
import ProductPromo, { ProductPromoType } from '.';
import { Account, AppContext } from '../../../models';
import { MOCK_SERVICES } from '../ConnectedServices/mocks';
import { MozServices } from '../../../lib/types';
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('ProductPromo', () => {

const { container } = renderWithLocalizationProvider(
<AppContext.Provider value={mockAppContext({ account })}>
<ProductPromo />
<ProductPromo type={ProductPromoType.Settings} />
</AppContext.Provider>
);

Expand All @@ -77,7 +77,7 @@ describe('ProductPromo', () => {
} as unknown as Account;
renderWithLocalizationProvider(
<AppContext.Provider value={mockAppContext({ account })}>
<ProductPromo />
<ProductPromo type={ProductPromoType.Settings} />
</AppContext.Provider>
);

Expand Down Expand Up @@ -105,7 +105,10 @@ describe('ProductPromo', () => {
} as unknown as Account;
renderWithLocalizationProvider(
<AppContext.Provider value={mockAppContext({ account })}>
<ProductPromo monitorPlusEnabled={true} />
<ProductPromo
monitorPlusEnabled={true}
type={ProductPromoType.Settings}
/>
</AppContext.Provider>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ export const ProductPromo = ({
? { event: { reason: 'plus' } }
: { event: { reason: 'free' } };

GleanMetrics.accountPref.promoMonitorView(gleanEvent);
// NOTE, this is a quick fix to prevent double 'view' event firing
// since we use this component in two places (sidebar + settings).
// We will want to refactor this to be less fragile.
if (type === ProductPromoType.Settings) {
GleanMetrics.accountPref.promoMonitorView(gleanEvent);
}

const promoContent = showMonitorPlusPromo ? (
<>
Expand Down Expand Up @@ -99,6 +104,10 @@ export const ProductPromo = ({
<LinkExternal
href={monitorPromoLink}
className="link-blue"
gleanDataAttrs={{
id: 'account_pref_promo_monitor_submit',
type: 'free',
}}
onClick={() => GleanMetrics.accountPref.promoMonitorSubmit(gleanEvent)}
>
<FtlMsg id="product-promo-monitor-cta">Get free scan</FtlMsg>
Expand Down

0 comments on commit bd68ab7

Please sign in to comment.