Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releast Analytics + Farcater URL changes #218

Closed
wants to merge 13 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
FarcasterRegistrationType,
SignerStatus,
} from ".";
import { isEqual, isUndefined, startsWith } from "lodash";
import { isEqual, isUndefined, replace, startsWith } from "lodash";
import { ed25519 } from "@noble/curves/ed25519";
import { bytesToHex, hexToBytes } from "@noble/ciphers/utils";
import axiosBackend from "@/common/data/api/backend";
Expand Down Expand Up @@ -223,16 +223,20 @@ const initializer: AuthenticatorInitializer<
};
});

const warpcastSignerUrl = data.signerUrl
? replace(data.signerUrl, "farcaster://", "https://warpcast.com/")
: undefined;

return (
<>
{isUndefined(data.status) ||
!isDataInitialized(data) ||
data.status === "revoked" ? (
<Button onClick={createSigner}>Link Warpcast Account</Button>
) : loading && data.signerUrl ? (
) : loading && warpcastSignerUrl ? (
<>
<QRCode value={data.signerUrl} maxWidth={256} />
<Link href={data.signerUrl}>
<QRCode value={warpcastSignerUrl} maxWidth={256} />
<Link href={warpcastSignerUrl}>
<p>On mobile? Click here</p>
</Link>
</>
Expand Down
8 changes: 0 additions & 8 deletions src/common/components/organisms/FidgetSettingsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@ export const FidgetSettingsEditor: React.FC<FidgetSettingsEditorProps> = ({
setState(settings);
}, [settings]);

useEffect(() => {
setState(settings);
}, [settings]);

useEffect(() => {
setState(settings);
}, [settings]);

const _onSave = (e) => {
e.preventDefault();
onSave(state);
Expand Down
2 changes: 1 addition & 1 deletion src/common/data/stores/app/accounts/farcasterStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const farcasterStore = (
);
if (!isUndefined(data.value)) {
get().account.addFidToCurrentIdentity(data.value!.fid);
analytics.track(AnalyticsEvent.LINK_FID);
analytics.track(AnalyticsEvent.LINK_FID, { fid });
}
},
});
14 changes: 14 additions & 0 deletions src/common/lib/hooks/useCurrentFid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useAppStore } from "@/common/data/stores/app";
import { NounspaceDeveloperManagedSignerData } from "@/authenticators/farcaster/signers/NounspaceManagedSignerAuthenticator";

export const useCurrentFid = (): number | null => {
const data: NounspaceDeveloperManagedSignerData | undefined = useAppStore(
(state) => {
return state.account.authenticatorConfig["farcaster:nounspace"]?.data;
},
);
const fid = data?.accountFid;
return !fid || fid === 1 ? null : fid;
};

export default useCurrentFid;
16 changes: 9 additions & 7 deletions src/common/providers/AnalyticsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { ReactNode, useEffect } from "react";
import { useRouter } from "next/router";
import { AnalyticsBrowser } from "@segment/analytics-next";
import { useCurrentSpaceIdentityPublicKey } from "@/common/lib/hooks/useCurrentSpaceIdentityPublicKey";
import { useCurrentFid } from "@/common/lib/hooks/useCurrentFid";

export enum AnalyticsEvent {
SIGN_UP = "Sign Up",
Expand All @@ -16,7 +17,7 @@ export enum AnalyticsEvent {

type AnalyticsEventProperties = {
[AnalyticsEvent.SIGN_UP]: Record<string, never>;
[AnalyticsEvent.LINK_FID]: Record<string, never>;
[AnalyticsEvent.LINK_FID]: { fid: number };
[AnalyticsEvent.SAVE_SPACE_THEME]: Record<string, never>;
[AnalyticsEvent.SAVE_HOMEBASE_THEME]: Record<string, never>;
[AnalyticsEvent.ADD_FIDGET]: { fidgetType: string };
Expand All @@ -33,16 +34,17 @@ export const analytics = {
) => {
segment.track(eventName, properties);
},
identify: (id: string) => {
segment.identify(id);
identify: (id: string, properties: any) => {
segment.identify(id, properties);
},
};

export const AnalyticsProvider: React.FC<{ children: ReactNode }> = ({
children,
}) => {
const router = useRouter();
const userId = useCurrentSpaceIdentityPublicKey();
const fid = useCurrentFid();
const identityPublicKey = useCurrentSpaceIdentityPublicKey();
const writeKey = process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY;

useEffect(() => {
Expand All @@ -54,10 +56,10 @@ export const AnalyticsProvider: React.FC<{ children: ReactNode }> = ({
}, [writeKey]);

useEffect(() => {
if (userId) {
analytics.identify(userId);
if (identityPublicKey) {
analytics.identify(identityPublicKey, { fid });
}
}, [userId]);
}, [identityPublicKey, fid]);

useEffect(() => {
segment.page();
Expand Down
2 changes: 1 addition & 1 deletion src/fidgets/farcaster/components/CastRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from "react";
import React, { useState } from "react";
import { Properties } from "csstype";
import { mergeClasses as classNames } from "@/common/lib/utils/mergeClasses";
import {
Expand Down