import{withPathPrefix as s}from"@redocly/theme/core/utils";import{envConfig as c}from"../../../config/env-config.js";import{normalizeRouteSlug as a}from"../../../../utils/path/normalize-route-slug.js";import{buildScripts as u}from"./build-scripts.js";import{resolveBrowserHooksPath as g}from"./resolve-browser-hooks.js";async function h(){const r=c.isProductionEnv;return{id:"Google Analytics",requiredEntitlements:["analytics"],afterRoutesCreated(t){const n=t.getGlobalData()||{},o=n.analytics?.ga||{trackingId:""};o?.exclude||(o.exclude=[]),o.trackers={};for(const i of Object.values(n.products||{})){const e=i.configOverride?.analytics?.ga;!e||!r&&!e.includeInDevelopment||(e.exclude?.length&&o.exclude.push(...e.exclude),o.trackers[a(i.slug)]=e)}if(o.trackingId&&(r||o.includeInDevelopment)&&(o.trackers[a(s("/"))]={trackingId:o.trackingId,conversionId:o.conversionId,floodlightId:o.floodlightId,optimizeId:o.optimizeId}),t.setGlobalData({...n,analytics:{...n?.analytics,ga:o}}),!Object.keys(o.trackers).length)return;const{headComponents:d,postBodyComponents:l}=u(o);t.addSsrComponents(d,"head"),t.addSsrComponents(l,"postBody"),t.addBrowserPlugin(g())}}}export{h as googleAnalyticsPlugin};
