Skip to content

Commit

Permalink
feat: add support for solution-channel parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
wangela committed May 3, 2024
1 parent 2a51f2c commit 68786b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/__tests__/api-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ test('passes parameters to GoogleMapsAPILoader', () => {
version={'beta'}
language={'en'}
region={'us'}
solutionChannel={'test-channel_value'}
authReferrerPolicy={'origin'}></APIProvider>
);

Expand All @@ -76,6 +77,7 @@ test('passes parameters to GoogleMapsAPILoader', () => {
v: 'beta',
language: 'en',
region: 'us',
solutionChannel: 'test-channel_value',
authReferrerPolicy: 'origin'
});
});
Expand Down
13 changes: 11 additions & 2 deletions src/components/api-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ export type APIProviderProps = {
* Part of: https://developers.google.com/maps/documentation/javascript/url-params
*/
authReferrerPolicy?: string;
/**
* To understand usage and ways to improve our solutions, Google includes the
* `solution_channel` query parameter in API calls to gather information about
* code usage. You may opt out at any time by setting this attribute to an
* empty string. Read more in the
* [documentation](https://developers.google.com/maps/reporting-and-monitoring/reporting#solutions-usage).
*/
solutionChannel?: string;
/**
* A function that can be used to execute code after the Google Maps JavaScript API has been loaded.
*/
Expand Down Expand Up @@ -101,6 +109,7 @@ function useMapInstances() {
*/
function useGoogleMapsApiLoader(props: APIProviderProps) {
const {onLoad, apiKey, version, libraries = [], ...otherApiParams} = props;
const solutionChannel = props.solutionChannel || 'GMP_VISGL_react';

const [status, setStatus] = useState<APILoadingStatus>(
GoogleMapsApiLoader.loadingStatus
Expand All @@ -117,8 +126,8 @@ function useGoogleMapsApiLoader(props: APIProviderProps) {

const librariesString = useMemo(() => libraries?.join(','), [libraries]);
const serializedParams = useMemo(
() => JSON.stringify({apiKey, version, ...otherApiParams}),
[apiKey, version, otherApiParams]
() => JSON.stringify({apiKey, version, solutionChannel, ...otherApiParams}),
[apiKey, version, solutionChannel, otherApiParams]
);

const importLibrary: typeof google.maps.importLibrary = useCallback(
Expand Down

0 comments on commit 68786b0

Please sign in to comment.