diff --git a/src/analytics.js b/src/analytics.js index 527e9cd8..273ffb95 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -3,7 +3,8 @@ import { default as fetch } from "unfetch"; import { ajv } from "./data-validation"; -import { AddonBase, CLIENT_VERSION } from "./utils"; +import { AddonBase, getMetadataValue, CLIENT_VERSION } from "./utils"; +import { default as objectPath } from "object-path"; export const API_ENDPOINT = "/_/api/v2/analytics/"; @@ -29,17 +30,32 @@ export class AnalyticsAddon extends AddonBase { loadConfig(config) { this.config = config; - // Only register pageviews on non-external versions - if (this.config.versions.current.type !== "external") { - this.registerPageView(); + const versionType = objectPath.get( + this.config, + "versions.current.type", + null, + ); + + // Don't register pageviews on external versions + if (versionType === "external") { + return; } + + this.registerPageView(); } registerPageView() { + const httpStatus = getMetadataValue("readthedocs-http-status"); + const versionSlug = objectPath.get( + this.config, + "versions.current.slug", + null, + ); const params = { project: this.config.projects.current.slug, - version: this.config.versions.current.slug, + version: versionSlug, absolute_uri: window.location.href, + status: httpStatus, }; const url = API_ENDPOINT + "?" + new URLSearchParams(params).toString(); diff --git a/src/data-validation.js b/src/data-validation.js index 0d9a19d2..130b10a9 100644 --- a/src/data-validation.js +++ b/src/data-validation.js @@ -48,20 +48,6 @@ const addons_analytics = { }, }, }, - versions: { - type: "object", - required: ["current"], - properties: { - current: { - type: "object", - required: ["slug", "type"], - properties: { - slug: { type: "string" }, - type: { type: "string" }, - }, - }, - }, - }, }, }; diff --git a/tests/analytics.test.html b/tests/analytics.test.html index a996214e..9bc8bc18 100644 --- a/tests/analytics.test.html +++ b/tests/analytics.test.html @@ -1,4 +1,7 @@ + + +