Open Vadman97 opened 2 weeks ago
To implement cross-domain identification and allow the clientID to persist via a cookie for backfilling sessions, follow these steps:
Backend Changes:
AppendProperties
function in /backend/public-graph/graph/resolver.go
to handle cross-domain cookies.
func (r *Resolver) AppendProperties(ctx context.Context, sessionID int, properties map[string]string, propType Property) error {
// Existing code...
// Set cross-domain cookie for clientID
http.SetCookie(w, &http.Cookie{
Name: "clientID",
Value: clientID,
Path: "/",
Domain: ".yourdomain.com", // Set to your domain
HttpOnly: true,
Secure: true,
})
// Existing code...
}
Frontend Changes:
init
function in /sdk/firstload/src/index.tsx
to read and set the clientID from a cookie.
init: (projectID?: string | number, options?: HighlightOptions) => {
// Existing code...
let clientID = document.cookie.split('; ').find(row => row.startsWith('clientID='))?.split('=')[1];
if (!clientID) {
clientID = GenerateSecureID();
document.cookie = `clientID=${clientID}; path=/; domain=.yourdomain.com; Secure; HttpOnly`;
}
// Existing code...
}
Session Backfilling:
sessionIsBackfilled
function in /frontend/src/pages/Player/utils/utils.ts
correctly identifies sessions using the clientID.
export const sessionIsBackfilled = (session: Session): boolean => {
return !!session.clientID && !!session.identifier && !session.identified;
};
/backend/public-graph/graph/resolver.go /backend/model/model.go /sdk/firstload/src/index.tsx /sdk/client/src/index.tsx /frontend/src/pages/Player/utils/utils.ts /frontend/src/pages/Player/utils/utils.test.ts /docs-content/getting-started/2_frontend-backend-mapping.md
allow the clientID to persist via a cookie cross-domain for backfilling sessions