-
Notifications
You must be signed in to change notification settings - Fork 17
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
Examples to use on Next.js / SSR #39
Comments
Hi @albseb511 , our SDK is a typically a client side only library and does not by its nature support SSR. Regarding Next.js examples, we have added it our to-dos and will be adding an example project in the future. |
Got it. I've it working with next I guess. But typescript causes issues there. Was looking out for a solution. |
Kind of managed in this manner declare global {
interface Window {
clevertap: {
event: any[];
profile: any[];
account: any[];
}
}
}
import { useContext } from "react";
import { ApplicationStatus, DocumentType } from "../API";
import { CleverTapContext } from "./CleverTapProvider";
export enum CleverTapEvents {
viewed_screen = "viewed_screen",
}
export type CleverTapParameters = {
screen_name?: ScreenNames;
field_name?: string;
};
export type CleverTapProfileParams = {
Name?: string;
Identity: string | number;
Email: string;
Phone?: string;
Gender?: string;
DOB?: Date;
"MSG-email"?: boolean;
"MSG-push"?: boolean;
"MSG-sms"?: boolean;
"MSG-whatsapp"?: boolean;
};
export enum ScreenNames {
dashboard = "dashboard",
}
const useCleverTap = () => {
const clevertap = useContext(CleverTapContext)[0];
const fireEvent = (event: CleverTapEvents, params: CleverTapParameters) => {
clevertap.event.push(event, params);
};
const profilePush = (params: CleverTapProfileParams) => {
clevertap.profile.push({
Site: params,
});
};
const onUserLogin = (params: CleverTapProfileParams) => {
clevertap.onUserLogin.push({
Site: params,
});
};
return [
{
fireEvent,
profilePush,
onUserLogin,
},
];
};
export default useCleverTap; |
@albseb511 Kindly go through the sample Nextjs web app , using clevertap-web-sdk |
Hi @KambleSonam, |
some examples on setting up with Next.js will help
we have set it up anyway by adding it to _document.tsx
The text was updated successfully, but these errors were encountered: