@@ -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' ;
5861import { 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' ;
6171import AdBlockingRecoverySetupSuccessNotification from './components/dashboard/AdBlockingRecoverySetupSuccessNotification' ;
6272import { CORE_MODULES } from '@/js/googlesitekit/modules/datastore/constants' ;
6373import 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' ;
6481export { registerStore } from './datastore' ;
6582
6683export 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
243386export function registerNotifications ( notifications ) {
0 commit comments