Skip to content

Commit

Permalink
Changed type of channel to number
Browse files Browse the repository at this point in the history
  • Loading branch information
yashSangai committed Oct 23, 2024
1 parent 403c2cf commit ecf822a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/api-reference/components/api-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +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
[gmp-channel-usage]: https://developers.google.com/maps/reporting-and-monitoring/reporting#usage-tracking-per-channel
10 changes: 7 additions & 3 deletions src/components/api-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export type APIProviderProps = {
* empty string. Read more in the
* [documentation](https://developers.google.com/maps/reporting-and-monitoring/reporting#solutions-usage).
*/
channel?: string;
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
* Read more in the
* [documentation](https://developers.google.com/maps/reporting-and-monitoring/reporting#usage-tracking-per-channel)
*/
solutionChannel?: string;
Expand Down Expand Up @@ -179,7 +179,11 @@ function useGoogleMapsApiLoader(props: APIProviderProps) {
if (version) params.v = version;
if (librariesString?.length > 0) params.libraries = librariesString;

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

if (params.solutionChannel === undefined)
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/google-maps-api-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type ApiParams = {
language?: string;
region?: string;
libraries?: string;
channel?: string;
channel?: number;
solutionChannel?: string;
authReferrerPolicy?: string;
};
Expand Down Expand Up @@ -140,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

0 comments on commit ecf822a

Please sign in to comment.