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

fix: Exit parent function on shouldSkipTracking() #2656

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions editor.planx.uk/src/pages/FlowEditor/lib/analyticsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
const previousBreadcrumbs = usePrevious(breadcrumbs);

const trackVisibilityChange = () => {
skipUpdateIfNotTracking();
if (shouldSkipTracking()) return;

switch (document.visibilityState) {
case "hidden":
send(
Expand Down Expand Up @@ -285,14 +286,13 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
});
}

function skipUpdateIfNotTracking() {
if (!shouldTrackAnalytics || !lastVisibleNodeAnalyticsLogId) {
return;
}
function shouldSkipTracking() {
return (!shouldTrackAnalytics || !lastVisibleNodeAnalyticsLogId)
}

async function trackHelpClick(metadata?: HelpClickMetadata) {
skipUpdateIfNotTracking();
if (shouldSkipTracking()) return;

await publicClient.mutate({
mutation: gql`
mutation UpdateHasClickedHelp($id: bigint!, $metadata: jsonb = {}) {
Expand All @@ -313,7 +313,8 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
}

async function trackNextStepsLinkClick(metadata?: SelectedUrlsMetadata) {
skipUpdateIfNotTracking();
if (shouldSkipTracking()) return;

await publicClient.mutate({
mutation: gql`
mutation UpdateHasClickNextStepsLink(
Expand All @@ -338,7 +339,8 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
async function trackFlowDirectionChange(
flowDirection: AnalyticsLogDirection,
) {
skipUpdateIfNotTracking();
if (shouldSkipTracking()) return;

await publicClient.mutate({
mutation: gql`
mutation UpdateFlowDirection($id: bigint!, $flow_direction: String) {
Expand All @@ -361,7 +363,8 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
initiator: BackwardsNavigationInitiatorType,
nodeId?: string,
) {
skipUpdateIfNotTracking();
if (shouldSkipTracking()) return;

const targetNodeMetadata = nodeId ? getTargetNodeDataFromFlow(nodeId) : {};
const metadata: Record<string, NodeMetadata> = {};
metadata[`${initiator}`] = targetNodeMetadata;
Expand Down Expand Up @@ -426,7 +429,8 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
}

async function updateLastVisibleNodeLogWithAllowListAnswers(nodeId: string) {
skipUpdateIfNotTracking();
if (shouldSkipTracking()) return;


const allowListAnswers = getAllowListAnswers(nodeId);
if (!allowListAnswers) return;
Expand Down Expand Up @@ -505,7 +509,8 @@ export const AnalyticsProvider: React.FC<{ children: React.ReactNode }> = ({
* Capture user input errors caught by ErrorWrapper component
*/
async function trackInputErrors(error: string) {
skipUpdateIfNotTracking();
if (shouldSkipTracking()) return;

await publicClient.mutate({
mutation: gql`
mutation TrackInputErrors($id: bigint!, $error: jsonb) {
Expand Down
Loading