From 2fcf614830b3dd6bafd21499eb5c3576a8955326 Mon Sep 17 00:00:00 2001
From: Daniel Leroux
Date: Mon, 17 Jun 2024 11:13:21 +0200
Subject: [PATCH] docs: load adobe analytics only once
---
packages/documentation/src/theme/Root.tsx | 30 +++-
.../src/theme/SiteMetadata/index.tsx | 158 ------------------
2 files changed, 29 insertions(+), 159 deletions(-)
delete mode 100644 packages/documentation/src/theme/SiteMetadata/index.tsx
diff --git a/packages/documentation/src/theme/Root.tsx b/packages/documentation/src/theme/Root.tsx
index 174486ffc6..00534b9ba9 100644
--- a/packages/documentation/src/theme/Root.tsx
+++ b/packages/documentation/src/theme/Root.tsx
@@ -8,7 +8,7 @@
*/
import { useLocation } from '@docusaurus/router';
-import React, { useEffect } from 'react';
+import React, { useEffect, useLayoutEffect } from 'react';
declare global {
interface Window {
@@ -36,5 +36,33 @@ export default function Root({ children }) {
});
}, [pathname]);
+ useLayoutEffect(() => {
+ const isAlreadyLoaded = document.head.querySelector(
+ 'meta[name="adobe-loaded"]'
+ );
+ if (!isAlreadyLoaded) {
+ const script = document.createElement('script');
+ script.setAttribute('no-cors', '');
+ script.src = '//w3.siemens.com/ote/ote_config.js';
+ document.head.appendChild(script);
+
+ const script2 = document.createElement('script');
+ script2.src = '//w3.siemens.com/ote/global/ote.js';
+ document.head.appendChild(script2);
+
+ const script3 = document.createElement('script');
+ script3.src =
+ 'https://assets.adobedtm.com/5dfc7d97c6fb/7699a47b720a/launch-2157063140e5.min.js';
+ script3.async = true;
+ document.head.appendChild(script3);
+
+ const meta = document.createElement('meta');
+ meta.name = 'adobe-loaded';
+ meta.content = 'true';
+
+ document.head.appendChild(meta);
+ }
+ }, []);
+
return <>{children}>;
}
diff --git a/packages/documentation/src/theme/SiteMetadata/index.tsx b/packages/documentation/src/theme/SiteMetadata/index.tsx
deleted file mode 100644
index c537c37366..0000000000
--- a/packages/documentation/src/theme/SiteMetadata/index.tsx
+++ /dev/null
@@ -1,158 +0,0 @@
-import React from 'react';
-import Head from '@docusaurus/Head';
-import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
-import useBaseUrl from '@docusaurus/useBaseUrl';
-import { PageMetadata, useThemeConfig } from '@docusaurus/theme-common';
-import {
- DEFAULT_SEARCH_TAG,
- useAlternatePageUtils,
- keyboardFocusedClassName,
-} from '@docusaurus/theme-common/internal';
-import { useLocation } from '@docusaurus/router';
-import { applyTrailingSlash } from '@docusaurus/utils-common';
-import SearchMetadata from '@theme/SearchMetadata';
-
-// TODO move to SiteMetadataDefaults or theme-common ?
-// Useful for i18n/SEO
-// See https://developers.google.com/search/docs/advanced/crawling/localized-versions
-// See https://github.com/facebook/docusaurus/issues/3317
-function AlternateLangHeaders(): JSX.Element {
- const {
- i18n: { currentLocale, defaultLocale, localeConfigs },
- } = useDocusaurusContext();
- const alternatePageUtils = useAlternatePageUtils();
-
- const currentHtmlLang = localeConfigs[currentLocale]!.htmlLang;
-
- // HTML lang is a BCP 47 tag, but the Open Graph protocol requires
- // using underscores instead of dashes.
- // See https://ogp.me/#optional
- // See https://en.wikipedia.org/wiki/IETF_language_tag)
- const bcp47ToOpenGraphLocale = (code: string): string =>
- code.replace('-', '_');
-
- // Note: it is fine to use both "x-default" and "en" to target the same url
- // See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
- return (
-
- {Object.entries(localeConfigs).map(([locale, { htmlLang }]) => (
-
- ))}
-
-
-
- {Object.values(localeConfigs)
- .filter((config) => currentHtmlLang !== config.htmlLang)
- .map((config) => (
-
- ))}
-
- );
-}
-
-// Default canonical url inferred from current page location pathname
-function useDefaultCanonicalUrl() {
- const {
- siteConfig: { url: siteUrl, baseUrl, trailingSlash },
- } = useDocusaurusContext();
-
- // TODO using useLocation().pathname is not a super idea
- // See https://github.com/facebook/docusaurus/issues/9170
- const { pathname } = useLocation();
-
- const canonicalPathname = applyTrailingSlash(useBaseUrl(pathname), {
- trailingSlash,
- baseUrl,
- });
-
- return siteUrl + canonicalPathname;
-}
-
-// TODO move to SiteMetadataDefaults or theme-common ?
-function CanonicalUrlHeaders({ permalink }: { permalink?: string }) {
- const {
- siteConfig: { url: siteUrl },
- } = useDocusaurusContext();
- const defaultCanonicalUrl = useDefaultCanonicalUrl();
-
- const canonicalUrl = permalink
- ? `${siteUrl}${permalink}`
- : defaultCanonicalUrl;
- return (
-
-
-
-
- );
-}
-
-export default function SiteMetadata(): JSX.Element {
- const {
- i18n: { currentLocale },
- } = useDocusaurusContext();
-
- // TODO maybe move these 2 themeConfig to siteConfig?
- // These seems useful for other themes as well
- const { metadata, image: defaultImage } = useThemeConfig();
-
- return (
- <>
-
-
-
-
-
- {defaultImage && }
-
-
-
-
-
-
-
- {/*
- It's important to have an additional
element here, as it allows
- react-helmet to override default metadata values set in previous
- like "twitter:card". In same Head, the same meta would appear twice
- instead of overriding.
- */}
-
- {/* Yes, "metadatum" is the grammatically correct term */}
- {metadata.map((metadatum, i) => (
-
- ))}
-
-
-
-
-
-
-
- >
- );
-}