diff --git a/.changeset/polite-poets-teach.md b/.changeset/polite-poets-teach.md
new file mode 100644
index 00000000000..1f66f76b7b6
--- /dev/null
+++ b/.changeset/polite-poets-teach.md
@@ -0,0 +1,5 @@
+---
+'@apollo/server': minor
+---
+
+We now send your @apollo/server version to the embedded Explorer & Sandbox used in the landing pages for analytics.
diff --git a/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts b/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts
index 0e2ecba05cd..0682cd06819 100644
--- a/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts
+++ b/packages/server/src/__tests__/plugin/landingPage/getEmbeddedExplorerHTML.test.ts
@@ -2,8 +2,9 @@ import { getEmbeddedExplorerHTML } from '../../../plugin/landingPage/default/get
import type { ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions } from '../../../plugin/landingPage/default/types';
import { describe, it, expect } from '@jest/globals';
-const version = '_latest';
+const cdnVersion = '_latest';
expect.addSnapshotSerializer(require('jest-serializer-html'));
+const apolloServerVersion = '@apollo/server@4.0.0';
describe('Embedded Explorer Landing Page Config HTML', () => {
it('with document, variables, headers and displayOptions provided', () => {
@@ -29,7 +30,8 @@ describe('Embedded Explorer Landing Page Config HTML', () => {
},
graphRef: 'graph@current',
};
- expect(getEmbeddedExplorerHTML(version, config)).toMatchInlineSnapshot(`
+ expect(getEmbeddedExplorerHTML(cdnVersion, config, apolloServerVersion))
+ .toMatchInlineSnapshot(`
Welcome to Apollo Server
@@ -47,11 +49,11 @@ describe('Embedded Explorer Landing Page Config HTML', () => {
id="embeddableExplorer"
>
-
`);
@@ -57,7 +60,8 @@ describe('Landing Page Config HTML', () => {
includeCookies: false,
embed: true,
};
- expect(getEmbeddedSandboxHTML(version, config)).toMatchInlineSnapshot(`
+ expect(getEmbeddedSandboxHTML(cdnVersion, config, apolloServerVersion))
+ .toMatchInlineSnapshot(`
Welcome to Apollo Server
@@ -75,7 +79,7 @@ describe('Landing Page Config HTML', () => {
id="embeddableSandbox"
>
-
`);
diff --git a/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts b/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts
index f13015d3b1b..85f9e79ae55 100644
--- a/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts
+++ b/packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts
@@ -21,8 +21,9 @@ function getConfigStringForHtml(config: LandingPageConfig) {
}
export const getEmbeddedExplorerHTML = (
- version: string,
+ explorerCdnVersion: string,
config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions,
+ apolloServerVersion: string,
) => {
interface EmbeddableExplorerOptions {
graphRef: string;
@@ -49,22 +50,25 @@ export const getEmbeddedExplorerHTML = (
persistExplorerState: false,
...(typeof config.embed === 'boolean' ? {} : config.embed),
};
- const embeddedExplorerParams: Omit =
- {
- graphRef: config.graphRef,
- target: '#embeddableExplorer',
- initialState: {
- document: config.document,
- headers: config.headers,
- variables: config.variables,
- displayOptions: {
- ...productionLandingPageConfigOrDefault.displayOptions,
- },
+ const embeddedExplorerParams: Omit<
+ EmbeddableExplorerOptions,
+ 'endpointUrl'
+ > & { runtime: string } = {
+ graphRef: config.graphRef,
+ target: '#embeddableExplorer',
+ initialState: {
+ document: config.document,
+ headers: config.headers,
+ variables: config.variables,
+ displayOptions: {
+ ...productionLandingPageConfigOrDefault.displayOptions,
},
- persistExplorerState:
- productionLandingPageConfigOrDefault.persistExplorerState,
- includeCookies: config.includeCookies,
- };
+ },
+ persistExplorerState:
+ productionLandingPageConfigOrDefault.persistExplorerState,
+ includeCookies: config.includeCookies,
+ runtime: apolloServerVersion,
+ };
return `
@@ -80,7 +84,11 @@ export const getEmbeddedExplorerHTML = (
style="width: 100vw; height: 100vh; position: absolute; top: 0;"
id="embeddableExplorer"
>
-
+
+
`;
diff --git a/packages/server/src/plugin/landingPage/default/index.ts b/packages/server/src/plugin/landingPage/default/index.ts
index 4371f91f93a..3b5af1e10e8 100644
--- a/packages/server/src/plugin/landingPage/default/index.ts
+++ b/packages/server/src/plugin/landingPage/default/index.ts
@@ -12,6 +12,7 @@ import {
getEmbeddedExplorerHTML,
getEmbeddedSandboxHTML,
} from './getEmbeddedHTML.js';
+import { packageVersion } from '../../../generated/packageVersion.js';
export type {
ApolloServerPluginLandingPageLocalDefaultOptions,
@@ -57,8 +58,9 @@ function encodeConfig(config: LandingPageConfig): string {
}
const getNonEmbeddedLandingPageHTML = (
- version: string,
+ cdnVersion: string,
config: LandingPageConfig,
+ apolloServerVersion: string,
) => {
const encodedConfig = encodeConfig(config);
@@ -68,7 +70,7 @@ const getNonEmbeddedLandingPageHTML = (
The full landing page cannot be loaded; it appears that you might be offline.
-`;
+`;
};
// Helper for the two actual plugin functions.
@@ -80,6 +82,7 @@ function ApolloServerPluginLandingPageDefault(
},
): ImplicitlyInstallablePlugin {
const version = maybeVersion ?? '_latest';
+ const apolloServerVersion = `@apollo/server@${packageVersion}`;
return {
__internal_installed_implicitly__: false,
@@ -132,9 +135,9 @@ function ApolloServerPluginLandingPageDefault(
${
config.embed
? 'graphRef' in config && config.graphRef
- ? getEmbeddedExplorerHTML(version, config)
- : getEmbeddedSandboxHTML(version, config)
- : getNonEmbeddedLandingPageHTML(version, config)
+ ? getEmbeddedExplorerHTML(version, config, apolloServerVersion)
+ : getEmbeddedSandboxHTML(version, config, apolloServerVersion)
+ : getNonEmbeddedLandingPageHTML(version, config, apolloServerVersion)
}