Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
use effect to send initial segment message
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhong committed Oct 5, 2023
1 parent d14fb8f commit 360bcd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/components/feedback/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ const Feedback = (props) => {
}
}, [helpful]);

useEffect(() => {
if (isOpen) {
// Add row to Segment when the user first interacts with the component
sendToSegment({ state: gatherState(), props });
}
}, [isOpen]);

function gatherState() {
return {
user,
Expand Down Expand Up @@ -81,9 +88,6 @@ const Feedback = (props) => {
setAnonymousId(anAnonymousId);
setSessionId(`${Date.now()}-${anAnonymousId}`);
setIsOpen(true);

// Add row to Segment
sendToSegment({ state: gatherState(), props });
}

function handleCategoryTypeChange(value) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/feedback/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import env from '../analytics-shell/env';
// Send the event to Segment with forward event
export function sendToSegment({ state, props }) {
const event = createSegmentEvent({ state, props });
console.log('segmentEvent', event)
forwardEvent(event, props.webhook, (err) => {
if (err) Sentry.captureException(err);
});
Expand All @@ -26,6 +25,7 @@ function createSegmentEvent({ state, props }) {
} = state;
const { site, section, location } = props;
// set user if available else set anonymousId (needed for forward-event request)
console.log('HERE', user, anonymousId);
const identity = {
...(user && user.id ? { userId: user.id } : { anonymousId: anonymousId })
};
Expand Down

0 comments on commit 360bcd2

Please sign in to comment.