Skip to content

Commit

Permalink
feat: calculator track events when values change (#215)
Browse files Browse the repository at this point in the history
- Tracks current value on mouse up / touch end for the value sliders.
- Tracks current values when select / dropdown inputs change.
  • Loading branch information
skylarmb authored Sep 12, 2024
1 parent 9aa6af7 commit 7a16e40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 21 additions & 2 deletions website/components/Calculator/CalculatorInputs.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"use client";

import { FiArrowRight, FiChevronDown } from "react-icons/fi";
import { useEffect } from "react";
import { FiChevronDown } from "react-icons/fi";
import styled from "styled-components";

import { ButtonPrimary } from "@/components/Button";
import { tablet } from "@/constants/breakpoints";
import { ResourceRequirement } from "@/constants/calculator";
import {
CostInterval,
useCalculatorContext,
} from "@/context/CalculatorContext";
import analytics from "@/lib/analytics";

const resourceRequirementsOptions: ResourceRequirement[] = [
ResourceRequirement.MICRO,
Expand All @@ -31,6 +32,20 @@ const CostSavingsCalculator = () => {
setCostInterval,
} = useCalculatorContext();

const trackCalculate = () => {
analytics.track("CALCULATE", {
numEngineers: engineers,
numServices: microservices,
costInterval,
resourceRequirement,
});
};

useEffect(() => {
trackCalculate();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [costInterval, resourceRequirement]);

return (
<S.Wrapper>
<S.Columns>
Expand All @@ -41,6 +56,8 @@ const CostSavingsCalculator = () => {
<S.Slider
value={engineers}
onChange={(e) => setEngineers(parseInt(e.target.value))}
onMouseUp={trackCalculate}
onTouchEnd={trackCalculate}
/>
<S.SliderValue $value={engineers}>{engineers}</S.SliderValue>
</S.SliderContainer>
Expand All @@ -52,6 +69,8 @@ const CostSavingsCalculator = () => {
<S.Slider
value={microservices}
onChange={(e) => setMicroservices(parseInt(e.target.value))}
onMouseUp={trackCalculate}
onTouchEnd={trackCalculate}
/>
<S.SliderValue role="presentation" $value={microservices}>
{microservices}
Expand Down
2 changes: 2 additions & 0 deletions website/lib/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ interface Payload {
// CALCULATE payload
numEngineers?: number;
numServices?: number;
costInterval?: string;
resourceRequirement?: string;

// FORM_SUBMIT payload
formType?: string; // which form is the user submitting
Expand Down

0 comments on commit 7a16e40

Please sign in to comment.