Skip to content

Commit

Permalink
fix(web): use ga4 on classic (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice authored Sep 26, 2023
1 parent 3e3549b commit 90a46f8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions web/src/classic/components/molecules/Visualizer/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Rectangle, Cartographic, Math as CesiumMath } from "cesium";
import { useRef, useEffect, useMemo, useState, useCallback, RefObject, useReducer } from "react";
import { initialize, pageview } from "react-ga";
import reactGA from "react-ga";
import reactGA4 from "react-ga4";
import { useSet } from "react-use";

import { useDrop, DropOptions } from "@reearth/classic/util/use-dnd";
Expand Down Expand Up @@ -206,11 +207,15 @@ export default ({

// GA
const { enableGA, trackingId } = sceneProperty?.googleAnalytics || {};

useEffect(() => {
if (!isPublished || !enableGA || !trackingId) return;
initialize(trackingId);
pageview(window.location.pathname);
if (trackingId.startsWith("G-")) {
reactGA4.initialize(trackingId);
reactGA4.send({ hitType: "pageview", page: window.location.pathname });
} else {
reactGA.initialize(trackingId);
reactGA.pageview(window.location.pathname);
}
}, [isPublished, enableGA, trackingId]);

const { overriddenAlignSystem, moveWidget } = useWidgetAlignSystem({
Expand Down

0 comments on commit 90a46f8

Please sign in to comment.