2023-08-25 11:33:14 +03:00
|
|
|
"use client";
|
2023-06-26 12:36:15 +03:00
|
|
|
import { AnalyticsBrowser } from "@june-so/analytics-next";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
|
|
|
const juneApiKey = process.env.NEXT_PUBLIC_JUNE_API_KEY;
|
|
|
|
|
|
|
|
export const useJune = (): AnalyticsBrowser | undefined => {
|
|
|
|
const [analytics, setAnalytics] = useState<AnalyticsBrowser | undefined>(
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const loadAnalytics = () => {
|
|
|
|
if (juneApiKey === undefined) {
|
2023-08-25 11:33:14 +03:00
|
|
|
console.log("No June API key found");
|
|
|
|
|
2023-06-26 12:36:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const response = AnalyticsBrowser.load({
|
|
|
|
writeKey: juneApiKey,
|
|
|
|
});
|
2023-08-25 11:33:14 +03:00
|
|
|
console.log("Loaded June Analytics", response);
|
2023-06-26 12:36:15 +03:00
|
|
|
setAnalytics(response);
|
|
|
|
};
|
|
|
|
loadAnalytics();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return analytics;
|
|
|
|
};
|