Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channel Prop Addition in APIProvider Component #584

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/api-reference/components/api-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ when authorizing requests from the Maps JavaScript API.
A list of [libraries][gmp-libs] to load immediately
(libraries can also be loaded later with the `useMapsLibrary` hook).

#### `channel`: number

To track usage of Google Maps JavaScript API via numeric channels. The only acceptable channel values are numbers from 0-999. Read more in the [documentation][gmp-channel-usage].

#### `solutionChannel`: string

To help Google to better understand types of usage of the Google Maps
Expand Down Expand Up @@ -163,3 +167,4 @@ The following hooks are built to work with the `APIProvider` Component:
[gmp-solutions-usage]: https://developers.google.com/maps/reporting-and-monitoring/reporting#solutions-usage
[api-provider-src]: https://github.com/visgl/react-google-maps/blob/main/src/components/api-provider.tsx
[rgm-new-issue]: https://github.com/visgl/react-google-maps/issues/new/choose
[gmp-channel-usage]: https://developers.google.com/maps/reporting-and-monitoring/reporting#usage-tracking-per-channel
13 changes: 13 additions & 0 deletions src/components/api-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export type APIProviderProps = {
* empty string. Read more in the
* [documentation](https://developers.google.com/maps/reporting-and-monitoring/reporting#solutions-usage).
*/
channel?: number;
/**
* To track usage of Google Maps JavaScript API via numeric channels. The only acceptable channel values are numbers from 0-999.
* Read more in the
* [documentation](https://developers.google.com/maps/reporting-and-monitoring/reporting#usage-tracking-per-channel)
*/
solutionChannel?: string;
/**
* A function that can be used to execute code after the Google Maps JavaScript API has been loaded.
Expand Down Expand Up @@ -173,6 +179,13 @@ function useGoogleMapsApiLoader(props: APIProviderProps) {
if (version) params.v = version;
if (librariesString?.length > 0) params.libraries = librariesString;

if (
params.channel === undefined ||
params.channel < 0 ||
params.channel > 999
)
delete params.channel;

if (params.solutionChannel === undefined)
params.solutionChannel = DEFAULT_SOLUTION_CHANNEL;
else if (params.solutionChannel === '') delete params.solutionChannel;
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/google-maps-api-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type ApiParams = {
language?: string;
region?: string;
libraries?: string;
channel?: number;
solutionChannel?: string;
authReferrerPolicy?: string;
};
Expand Down Expand Up @@ -139,7 +140,7 @@ export class GoogleMapsApiLoader {
/[A-Z]/g,
t => '_' + t[0].toLowerCase()
);
urlParams.set(urlParamName, value);
urlParams.set(urlParamName, String(value));
}
urlParams.set('loading', 'async');
urlParams.set('callback', '__googleMapsCallback__');
Expand Down