Skip to content

Commit

Permalink
update telemetry endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlurie committed Dec 11, 2024
1 parent 58d2c29 commit 5a0d810
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## NEXT
### New Features
- New `MaptilerProjectionControl` to toggle globe/Mercator projection
- Add metric collection and plugin registration feature

### Bug Fixes
- Navigation now relies on `Map` methods instead of `Transform` methods for bearing due to globe projection being available
Expand Down
19 changes: 13 additions & 6 deletions src/Telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,20 @@ export class Telemetry {
this.map = map;

setTimeout(
() => {
async () => {
if (!config.telemetry) {
return;
}

const endpointURL = this.preparePayload();
console.log(endpointURL);

try {
const response = await fetch(endpointURL, { method: "POST" });
if (!response.ok) {
console.warn("The metrics could not be sent to MapTiler Cloud");
}
} catch (e) {
console.warn("The metrics could not be sent to MapTiler Cloud", e);
}
},
Math.max(1000, delay),
);
Expand Down Expand Up @@ -68,13 +75,13 @@ export class Telemetry {
telemetryUrl.searchParams.append("globe", this.map.isGlobeProjection() ? "1" : "0");

// Adding the modules
// the list of modules are separated by a "|". For each module, a "*" is used to separate the name and the version:
// "@maptiler/module-foo*1.1.0|@maptiler/module-bar*3.4.0|@maptiler/module-baz*9.0.3|@maptiler/module-quz*0.0.2-rc.1"
// the list of modules are separated by a "|". For each module, a ":" is used to separate the name and the version:
// "@maptiler/module-foo:1.1.0|@maptiler/module-bar:3.4.0|@maptiler/module-baz:9.0.3|@maptiler/module-quz:0.0.2-rc.1"
// then the `.append()` function is in charge of URL-encoding the argument
if (this.registeredModules.length) {
telemetryUrl.searchParams.append(
"modules",
this.registeredModules.map((module) => `${module.name}*${module.version}`).join("|"),
this.registeredModules.map((module) => `${module.name}:${module.version}`).join("|"),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const defaults = {
maptilerLogoURL: "https://api.maptiler.com/resources/logo.svg",
maptilerURL: "https://www.maptiler.com/",
maptilerApiHost: "api.maptiler.com",
telemetryURL: "https://api.maptiler.com/telemetry",
telemetryURL: "https://api.maptiler.com/metrics",
rtlPluginURL: "https://cdn.maptiler.com/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.min.js",
primaryLanguage: Language.STYLE,
secondaryLanguage: Language.LOCAL,
Expand Down

0 comments on commit 5a0d810

Please sign in to comment.