import{withPathPrefix as s}from"@redocly/theme/core/utils";import{isProductionMode as c}from"../../../../shared/env.js";import{buildScripts as l}from"./build-scripts.js";import{resolveBrowserHooksPath as u}from"./resolve-browser-hooks.js";async function I(){const r=c();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[i.slug]=e)}if(o.trackingId&&(r||o.includeInDevelopment)&&(o.trackers[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:a,postBodyComponents:d}=l(o);t.addSsrComponents(a,"head"),t.addSsrComponents(d,"postBody"),t.addBrowserPlugin(u())}}}export{I as googleAnalyticsPlugin};
