diff --git a/docusaurus.config.js b/docusaurus.config.js index 3ec2c4291e..6cbee2f502 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -155,6 +155,27 @@ module.exports = { }, }), }, + // Meta Pixel Code + { + tagName: "script", + attributes: {}, + innerHTML: `!function(f,b,e,v,n,t,s) +{if(f.fbq)return;n=f.fbq=function(){n.callMethod? +n.callMethod.apply(n,arguments):n.queue.push(arguments)}; +if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0'; +n.queue=[];t=b.createElement(e);t.async=!0; +t.src=v;s=b.getElementsByTagName(e)[0]; +s.parentNode.insertBefore(t,s)}(window, document,'script', +'https://connect.facebook.net/en_US/fbevents.js'); +fbq('init', '2006330080011702'); +fbq('track', 'PageView');`, + }, + { + tagName: "noscript", + attributes: {}, + innerHTML: ``, + }, + // End Meta Pixel Code ], title: "Keploy Documentation", titleDelimiter: "🐰", @@ -549,6 +570,7 @@ module.exports = { ], ], + clientModules: [require.resolve("./src/metaPixelRouteTracker.js")], scripts: [ { src: "/docs/scripts/feedback.js", diff --git a/src/metaPixelRouteTracker.js b/src/metaPixelRouteTracker.js new file mode 100644 index 0000000000..f11e9488d7 --- /dev/null +++ b/src/metaPixelRouteTracker.js @@ -0,0 +1,11 @@ +// Re-fire Meta Pixel PageView on client-side route changes. +// The base snippet in docusaurus.config.js (headTags) only fires PageView on +// the initial load; Docusaurus is an SPA, so in-app navigation must be tracked +// explicitly here. +export function onRouteDidUpdate({location, previousLocation}) { + if (previousLocation && location.pathname !== previousLocation.pathname) { + if (typeof window.fbq === "function") { + window.fbq("track", "PageView"); + } + } +}