-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
226 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
assets/js/modules/analytics-4/datastore/conversion-reporting.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* `modules/analytics-4` data store: conversion reporting. | ||
* | ||
* Site Kit by Google, Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { createRegistrySelector } from 'googlesitekit-data'; | ||
import { MODULES_ANALYTICS_4 } from './constants'; | ||
|
||
export const selectors = { | ||
/** | ||
* Checks whether the provided conversion reporting events are available. | ||
* | ||
* @since n.e.x.t | ||
* | ||
* @param {Object} state Data store's state. | ||
* @param {string|Array<string>} events Conversion reporting events to check. | ||
* @return {(boolean|undefined)} True if all provided custom dimensions are available, otherwise false. Undefined if available custom dimensions are not loaded yet. | ||
*/ | ||
hasConversionReportingEvents: createRegistrySelector( | ||
( select ) => ( state, events ) => { | ||
// Ensure events is always an array, even if a string is passed. | ||
const eventsToCheck = Array.isArray( events ) ? events : [ events ]; | ||
|
||
const detectedEvents = | ||
select( MODULES_ANALYTICS_4 ).getDetectedEvents(); | ||
|
||
if ( ! detectedEvents?.length ) { | ||
return false; | ||
} | ||
|
||
return eventsToCheck.some( ( event ) => | ||
detectedEvents.includes( event ) | ||
); | ||
} | ||
), | ||
}; | ||
|
||
export default { | ||
selectors, | ||
}; |
85 changes: 85 additions & 0 deletions
85
assets/js/modules/analytics-4/datastore/conversion-reporting.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* `modules/analytics-4` data store: conversion-reporting tests. | ||
* | ||
* Site Kit by Google, Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { MODULES_ANALYTICS_4 } from './constants'; | ||
import { | ||
createTestRegistry, | ||
provideModules, | ||
provideUserAuthentication, | ||
} from '../../../../../tests/js/utils'; | ||
|
||
describe( 'modules/analytics-4 conversion-reporting', () => { | ||
let registry; | ||
|
||
beforeEach( () => { | ||
registry = createTestRegistry(); | ||
|
||
provideUserAuthentication( registry ); | ||
provideModules( registry ); | ||
} ); | ||
|
||
describe( 'selectors', () => { | ||
describe( 'hasConversionReportingEvents', () => { | ||
it( 'returns false when no conversion reporting events are available', () => { | ||
registry | ||
.dispatch( MODULES_ANALYTICS_4 ) | ||
.setSettings( { detectedEvents: [] } ); | ||
|
||
const hasConversionReportingEvents = registry | ||
.select( MODULES_ANALYTICS_4 ) | ||
.hasConversionReportingEvents( [ 'test-event' ] ); | ||
|
||
expect( hasConversionReportingEvents ).toBe( false ); | ||
} ); | ||
|
||
it( 'returns true when provided conversion reporting event is available', () => { | ||
registry.dispatch( MODULES_ANALYTICS_4 ).setSettings( { | ||
detectedEvents: [ 'test-event', 'test-event-2' ], | ||
} ); | ||
|
||
const hasConversionReportingEvents = registry | ||
.select( MODULES_ANALYTICS_4 ) | ||
.hasConversionReportingEvents( [ 'test-event' ] ); | ||
|
||
expect( hasConversionReportingEvents ).toBe( true ); | ||
} ); | ||
|
||
it( 'returns true when some of provided conversion reporting events are available', () => { | ||
registry.dispatch( MODULES_ANALYTICS_4 ).setSettings( { | ||
detectedEvents: [ | ||
'test-event', | ||
'test-event-2', | ||
'test-event-3', | ||
], | ||
} ); | ||
|
||
const hasConversionReportingEvents = registry | ||
.select( MODULES_ANALYTICS_4 ) | ||
.hasConversionReportingEvents( [ | ||
'no-event', | ||
'test-event', | ||
] ); | ||
|
||
expect( hasConversionReportingEvents ).toBe( true ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.