Skip to content

Commit

Permalink
feat: execute tag manager script right before loading osano.js (#3379)
Browse files Browse the repository at this point in the history
* feat: execute tag manager script right before loading osano.js

* oops: remove console log

* refactor: rewrite as a plugin for more control over order of scripts
  • Loading branch information
pepopowitz authored Feb 27, 2024
1 parent 6d23351 commit afe641c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = {
// }
// },
// ],
// This custom Osano plugin must precede the gtm-plugin.
"./static/plugins/osano",
[
require.resolve("docusaurus-gtm-plugin"),
{
Expand Down
5 changes: 0 additions & 5 deletions src/theme/Footer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ import Footer from "@theme-original/Footer";

import { Auth0Provider, useAuth0 } from "@auth0/auth0-react";
import BrowserOnly from "@docusaurus/BrowserOnly";
import Head from "@docusaurus/Head";
import mixpanel from "mixpanel-browser";

export default function FooterWrapper(props) {
return (
<>
<Footer {...props} />
<Head>
{/* Osano (Consent) */}
<script src="https://cmp.osano.com/16CVvwSNKHi9t1grQ/2ce963c0-31c9-4b54-b052-d66a2a948ccc/osano.js"></script>
</Head>
<AnalyticsEvents></AnalyticsEvents>
</>
);
Expand Down
37 changes: 37 additions & 0 deletions static/plugins/osano/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This is implemented as a plugin because script order is important.
module.exports = function () {
return {
name: "osano-plugin",
injectHtmlTags() {
return {
headTags: [
{
tagName: "script",
innerHTML: `
// Required prior to loading osano.js script.
window.dataLayer = window.dataLayer || []
function gtag() {
dataLayer.push(arguments)
}
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
wait_for_update: 500,
})
gtag('set', 'ads_data_redaction', true)
`,
attributes: {},
},
{
tagName: "script",
attributes: {
src: "https://cmp.osano.com/16CVvwSNKHi9t1grQ/2ce963c0-31c9-4b54-b052-d66a2a948ccc/osano.js",
},
},
],
};
},
};
};

0 comments on commit afe641c

Please sign in to comment.