Skip to content

Commit 18e8ff5

Browse files
Merge pull request #11824 from google/enhancement/11699-move-adsense-notification-registrations
Enhancement/11699 Move AdSense notification registrations
2 parents 66f382a + e44f13f commit 18e8ff5

File tree

4 files changed

+150
-140
lines changed

4 files changed

+150
-140
lines changed

assets/js/components/OverlayNotification/AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification, {
5050
ANALYTICS_ADSENSE_LINKED_OVERLAY_NOTIFICATION,
5151
} from './AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification';
5252
import { withNotificationComponentProps } from '@/js/googlesitekit/notifications/util/component-props';
53-
import { DEFAULT_NOTIFICATIONS } from '@/js/googlesitekit/notifications/register-defaults';
53+
import { ADSENSE_NOTIFICATIONS } from '@/js/modules/adsense';
5454
import {
5555
NOTIFICATION_AREAS,
5656
NOTIFICATION_GROUPS,
@@ -65,7 +65,7 @@ describe( 'AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification', () =
6565
)( AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification );
6666

6767
const notification =
68-
DEFAULT_NOTIFICATIONS[ ANALYTICS_ADSENSE_LINKED_OVERLAY_NOTIFICATION ];
68+
ADSENSE_NOTIFICATIONS[ ANALYTICS_ADSENSE_LINKED_OVERLAY_NOTIFICATION ];
6969

7070
let registry;
7171

assets/js/components/OverlayNotification/LinkAnalyticsAndAdSenseAccountsOverlayNotification.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
} from '@/js/googlesitekit/constants';
4242
import { withNotificationComponentProps } from '@/js/googlesitekit/notifications/util/component-props';
4343
import { CORE_NOTIFICATIONS } from '@/js/googlesitekit/notifications/datastore/constants';
44-
import { DEFAULT_NOTIFICATIONS } from '@/js/googlesitekit/notifications/register-defaults';
44+
import { ADSENSE_NOTIFICATIONS } from '@/js/modules/adsense';
4545
import Notifications from '@/js/components/notifications/Notifications';
4646
import {
4747
NOTIFICATION_AREAS,
@@ -55,7 +55,7 @@ describe( 'LinkAnalyticsAndAdSenseAccountsOverlayNotification', () => {
5555
)( LinkAnalyticsAndAdSenseAccountsOverlayNotification );
5656

5757
const notification =
58-
DEFAULT_NOTIFICATIONS[ LINK_ANALYTICS_ADSENSE_OVERLAY_NOTIFICATION ];
58+
ADSENSE_NOTIFICATIONS[ LINK_ANALYTICS_ADSENSE_OVERLAY_NOTIFICATION ];
5959

6060
let registry;
6161

assets/js/googlesitekit/notifications/register-defaults.js

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
PERMISSION_UPDATE_PLUGINS,
5050
} from '@/js/googlesitekit/datastore/user/constants';
5151
import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants';
52-
import { MODULES_ADSENSE } from '@/js/modules/adsense/datastore/constants';
5352
import {
5453
DATE_RANGE_OFFSET,
5554
MODULES_ANALYTICS_4,
@@ -78,12 +77,6 @@ import { MINUTE_IN_SECONDS } from '@/js/util';
7877
import ModuleRecoveryAlert from '@/js/components/dashboard-sharing/ModuleRecoveryAlert';
7978
import SiteKitSetupSuccessNotification from '@/js/components/notifications/SiteKitSetupSuccessNotification';
8079
import ModuleSetupSuccessNotification from '@/js/components/notifications/ModuleSetupSuccessNotification';
81-
import AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification, {
82-
ANALYTICS_ADSENSE_LINKED_OVERLAY_NOTIFICATION,
83-
} from '@/js/components/OverlayNotification/AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification';
84-
import LinkAnalyticsAndAdSenseAccountsOverlayNotification, {
85-
LINK_ANALYTICS_ADSENSE_OVERLAY_NOTIFICATION,
86-
} from '@/js/components/OverlayNotification/LinkAnalyticsAndAdSenseAccountsOverlayNotification';
8780
import SetUpEmailReportingOverlayNotification, {
8881
SET_UP_EMAIL_REPORTING_OVERLAY_NOTIFICATION,
8982
} from '@/js/components/email-reporting/SetUpEmailReportingOverlayNotification';
@@ -690,132 +683,6 @@ export const DEFAULT_NOTIFICATIONS = {
690683
isDismissible: true,
691684
featureFlag: 'googleTagGateway',
692685
},
693-
[ ANALYTICS_ADSENSE_LINKED_OVERLAY_NOTIFICATION ]: {
694-
Component:
695-
AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification,
696-
priority: PRIORITY.SETUP_CTA_HIGH,
697-
areaSlug: NOTIFICATION_AREAS.OVERLAYS,
698-
groupID: NOTIFICATION_GROUPS.SETUP_CTAS,
699-
viewContexts: [
700-
VIEW_CONTEXT_MAIN_DASHBOARD,
701-
VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
702-
],
703-
isDismissible: true,
704-
checkRequirements: async ( { select, resolveSelect } ) => {
705-
await Promise.all( [
706-
// The hasAccessToShareableModule() selector relies on
707-
// the resolution of getAuthentication().
708-
resolveSelect( CORE_USER ).getAuthentication(),
709-
// The isModuleConnected() and hasAccessToShareableModule() selectors
710-
// rely on the resolution of the getModules() resolver.
711-
resolveSelect( CORE_MODULES ).getModules(),
712-
] );
713-
714-
const adSenseModuleConnected =
715-
select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ADSENSE );
716-
717-
const analyticsModuleConnected = select(
718-
CORE_MODULES
719-
).isModuleConnected( MODULE_SLUG_ANALYTICS_4 );
720-
721-
const canViewSharedAdsense =
722-
select( CORE_USER ).hasAccessToShareableModule(
723-
MODULE_SLUG_ADSENSE
724-
);
725-
726-
const canViewSharedAnalytics = select(
727-
CORE_USER
728-
).hasAccessToShareableModule( MODULE_SLUG_ANALYTICS_4 );
729-
730-
if (
731-
! (
732-
adSenseModuleConnected &&
733-
analyticsModuleConnected &&
734-
canViewSharedAdsense &&
735-
canViewSharedAnalytics
736-
)
737-
) {
738-
return false;
739-
}
740-
741-
// The getAdSenseLinked() selector relies on the resolution
742-
// of the getSettings() resolver.
743-
await resolveSelect( MODULES_ANALYTICS_4 ).getSettings();
744-
const isAdSenseLinked =
745-
select( MODULES_ANALYTICS_4 ).getAdSenseLinked();
746-
747-
if ( ! isAdSenseLinked ) {
748-
return false;
749-
}
750-
751-
// The getAccountID() selector relies on the resolution
752-
// of the getSettings() resolver.
753-
await resolveSelect( MODULES_ADSENSE ).getSettings();
754-
const adSenseAccountID = select( MODULES_ADSENSE ).getAccountID();
755-
756-
const { startDate, endDate } = select(
757-
CORE_USER
758-
).getDateRangeDates( {
759-
offsetDays: DATE_RANGE_OFFSET,
760-
} );
761-
762-
const reportArgs = {
763-
startDate,
764-
endDate,
765-
dimensions: [ 'pagePath', 'adSourceName' ],
766-
metrics: [ { name: 'totalAdRevenue' } ],
767-
dimensionFilters: {
768-
adSourceName: `Google AdSense account (${ adSenseAccountID })`,
769-
},
770-
orderby: [
771-
{ metric: { metricName: 'totalAdRevenue' }, desc: true },
772-
],
773-
limit: 1,
774-
reportID:
775-
'notifications_analytics-adsense-linked-overlay_reportArgs',
776-
};
777-
778-
const reportData = await resolveSelect(
779-
MODULES_ANALYTICS_4
780-
).getReport( reportArgs );
781-
782-
return isZeroReport( reportData ) === false;
783-
},
784-
},
785-
[ LINK_ANALYTICS_ADSENSE_OVERLAY_NOTIFICATION ]: {
786-
Component: LinkAnalyticsAndAdSenseAccountsOverlayNotification,
787-
priority: PRIORITY.SETUP_CTA_LOW,
788-
areaSlug: NOTIFICATION_AREAS.OVERLAYS,
789-
groupID: NOTIFICATION_GROUPS.SETUP_CTAS,
790-
viewContexts: [ VIEW_CONTEXT_MAIN_DASHBOARD ],
791-
isDismissible: true,
792-
checkRequirements: async ( { select, resolveSelect } ) => {
793-
await Promise.all( [
794-
// The isModuleConnected() selector relies on the resolution
795-
// of the getModules() resolver.
796-
resolveSelect( CORE_MODULES ).getModules(),
797-
] );
798-
799-
const adSenseModuleConnected =
800-
select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ADSENSE );
801-
802-
const analyticsModuleConnected = select(
803-
CORE_MODULES
804-
).isModuleConnected( MODULE_SLUG_ANALYTICS_4 );
805-
806-
if ( ! ( adSenseModuleConnected && analyticsModuleConnected ) ) {
807-
return false;
808-
}
809-
810-
// The getAdSenseLinked() selector relies on the resolution
811-
// of the getSettings() resolver.
812-
await resolveSelect( MODULES_ANALYTICS_4 ).getSettings();
813-
const isAdSenseLinked =
814-
select( MODULES_ANALYTICS_4 ).getAdSenseLinked();
815-
816-
return isAdSenseLinked === false;
817-
},
818-
},
819686
[ SET_UP_EMAIL_REPORTING_OVERLAY_NOTIFICATION ]: {
820687
Component: SetUpEmailReportingOverlayNotification,
821688
priority: PRIORITY.SETUP_CTA_LOW,

assets/js/modules/adsense/index.js

Lines changed: 146 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,30 @@ import {
5454
ERROR_CODE_ADBLOCKER_ACTIVE,
5555
KM_ANALYTICS_ADSENSE_TOP_EARNING_CONTENT,
5656
} from '@/js/googlesitekit/datastore/user/constants';
57-
import { MODULES_ANALYTICS_4 } from '@/js/modules/analytics-4/datastore/constants';
57+
import {
58+
MODULES_ANALYTICS_4,
59+
DATE_RANGE_OFFSET,
60+
} from '@/js/modules/analytics-4/datastore/constants';
5861
import { MODULE_SLUG_ANALYTICS_4 } from '@/js/modules/analytics-4/constants';
59-
import { NOTIFICATION_AREAS } from '@/js/googlesitekit/notifications/constants';
60-
import { VIEW_CONTEXT_MAIN_DASHBOARD } from '@/js/googlesitekit/constants';
62+
import {
63+
NOTIFICATION_AREAS,
64+
NOTIFICATION_GROUPS,
65+
PRIORITY,
66+
} from '@/js/googlesitekit/notifications/constants';
67+
import {
68+
VIEW_CONTEXT_MAIN_DASHBOARD,
69+
VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
70+
} from '@/js/googlesitekit/constants';
6171
import AdBlockingRecoverySetupSuccessNotification from './components/dashboard/AdBlockingRecoverySetupSuccessNotification';
6272
import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants';
6373
import DashboardMainEffectComponent from './components/DashboardMainEffectComponent';
74+
import AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification, {
75+
ANALYTICS_ADSENSE_LINKED_OVERLAY_NOTIFICATION,
76+
} from '@/js/components/OverlayNotification/AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification';
77+
import LinkAnalyticsAndAdSenseAccountsOverlayNotification, {
78+
LINK_ANALYTICS_ADSENSE_OVERLAY_NOTIFICATION,
79+
} from '@/js/components/OverlayNotification/LinkAnalyticsAndAdSenseAccountsOverlayNotification';
80+
import { isZeroReport } from '@/js/modules/analytics-4/utils';
6481
export { registerStore } from './datastore';
6582

6683
export function registerModule( modules ) {
@@ -238,6 +255,132 @@ export const ADSENSE_NOTIFICATIONS = {
238255
return false;
239256
},
240257
},
258+
[ ANALYTICS_ADSENSE_LINKED_OVERLAY_NOTIFICATION ]: {
259+
Component:
260+
AnalyticsAndAdSenseAccountsDetectedAsLinkedOverlayNotification,
261+
priority: PRIORITY.SETUP_CTA_HIGH,
262+
areaSlug: NOTIFICATION_AREAS.OVERLAYS,
263+
groupID: NOTIFICATION_GROUPS.SETUP_CTAS,
264+
viewContexts: [
265+
VIEW_CONTEXT_MAIN_DASHBOARD,
266+
VIEW_CONTEXT_MAIN_DASHBOARD_VIEW_ONLY,
267+
],
268+
isDismissible: true,
269+
checkRequirements: async ( { select, resolveSelect } ) => {
270+
await Promise.all( [
271+
// The hasAccessToShareableModule() selector relies on
272+
// the resolution of getAuthentication().
273+
resolveSelect( CORE_USER ).getAuthentication(),
274+
// The isModuleConnected() and hasAccessToShareableModule() selectors
275+
// rely on the resolution of the getModules() resolver.
276+
resolveSelect( CORE_MODULES ).getModules(),
277+
] );
278+
279+
const adSenseModuleConnected =
280+
select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ADSENSE );
281+
282+
const analyticsModuleConnected = select(
283+
CORE_MODULES
284+
).isModuleConnected( MODULE_SLUG_ANALYTICS_4 );
285+
286+
const canViewSharedAdsense =
287+
select( CORE_USER ).hasAccessToShareableModule(
288+
MODULE_SLUG_ADSENSE
289+
);
290+
291+
const canViewSharedAnalytics = select(
292+
CORE_USER
293+
).hasAccessToShareableModule( MODULE_SLUG_ANALYTICS_4 );
294+
295+
if (
296+
! (
297+
adSenseModuleConnected &&
298+
analyticsModuleConnected &&
299+
canViewSharedAdsense &&
300+
canViewSharedAnalytics
301+
)
302+
) {
303+
return false;
304+
}
305+
306+
// The getAdSenseLinked() selector relies on the resolution
307+
// of the getSettings() resolver.
308+
await resolveSelect( MODULES_ANALYTICS_4 ).getSettings();
309+
const isAdSenseLinked =
310+
select( MODULES_ANALYTICS_4 ).getAdSenseLinked();
311+
312+
if ( ! isAdSenseLinked ) {
313+
return false;
314+
}
315+
316+
// The getAccountID() selector relies on the resolution
317+
// of the getSettings() resolver.
318+
await resolveSelect( MODULES_ADSENSE ).getSettings();
319+
const adSenseAccountID = select( MODULES_ADSENSE ).getAccountID();
320+
321+
const { startDate, endDate } = select(
322+
CORE_USER
323+
).getDateRangeDates( {
324+
offsetDays: DATE_RANGE_OFFSET,
325+
} );
326+
327+
const reportArgs = {
328+
startDate,
329+
endDate,
330+
dimensions: [ 'pagePath', 'adSourceName' ],
331+
metrics: [ { name: 'totalAdRevenue' } ],
332+
dimensionFilters: {
333+
adSourceName: `Google AdSense account (${ adSenseAccountID })`,
334+
},
335+
orderby: [
336+
{ metric: { metricName: 'totalAdRevenue' }, desc: true },
337+
],
338+
limit: 1,
339+
reportID:
340+
'notifications_analytics-adsense-linked-overlay_reportArgs',
341+
};
342+
343+
const reportData = await resolveSelect(
344+
MODULES_ANALYTICS_4
345+
).getReport( reportArgs );
346+
347+
return isZeroReport( reportData ) === false;
348+
},
349+
},
350+
[ LINK_ANALYTICS_ADSENSE_OVERLAY_NOTIFICATION ]: {
351+
Component: LinkAnalyticsAndAdSenseAccountsOverlayNotification,
352+
priority: PRIORITY.SETUP_CTA_LOW,
353+
areaSlug: NOTIFICATION_AREAS.OVERLAYS,
354+
groupID: NOTIFICATION_GROUPS.SETUP_CTAS,
355+
viewContexts: [ VIEW_CONTEXT_MAIN_DASHBOARD ],
356+
isDismissible: true,
357+
checkRequirements: async ( { select, resolveSelect } ) => {
358+
await Promise.all( [
359+
// The isModuleConnected() selector relies on the resolution
360+
// of the getModules() resolver.
361+
resolveSelect( CORE_MODULES ).getModules(),
362+
] );
363+
364+
const adSenseModuleConnected =
365+
select( CORE_MODULES ).isModuleConnected( MODULE_SLUG_ADSENSE );
366+
367+
const analyticsModuleConnected = select(
368+
CORE_MODULES
369+
).isModuleConnected( MODULE_SLUG_ANALYTICS_4 );
370+
371+
if ( ! ( adSenseModuleConnected && analyticsModuleConnected ) ) {
372+
return false;
373+
}
374+
375+
// The getAdSenseLinked() selector relies on the resolution
376+
// of the getSettings() resolver.
377+
await resolveSelect( MODULES_ANALYTICS_4 ).getSettings();
378+
const isAdSenseLinked =
379+
select( MODULES_ANALYTICS_4 ).getAdSenseLinked();
380+
381+
return isAdSenseLinked === false;
382+
},
383+
},
241384
};
242385

243386
export function registerNotifications( notifications ) {

0 commit comments

Comments
 (0)