Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "ol-components"

import { RiAddLine } from "@remixicon/react"
import { usePostHog } from "posthog-js/react"

import * as NiceModal from "@ebay/nice-modal-react"

Expand Down Expand Up @@ -67,6 +68,7 @@ const AddToListDialogInner: React.FC<AddToListDialogInnerProps> = ({
isLoading: isSavingLearningPathRelationships,
mutateAsync: setLearningPathRelationships,
} = useLearningResourceSetLearningPathRelationships()
const posthog = usePostHog()
const isSaving =
isSavingLearningPathRelationships || isSavingUserListRelationships
let dialogTitle = "Add to list"
Expand All @@ -93,6 +95,9 @@ const AddToListDialogInner: React.FC<AddToListDialogInnerProps> = ({
: null,
)
.filter((value) => value !== null)

const { POSTHOG } = APP_SETTINGS

const formik = useFormik({
enableReinitialize: true,
validateOnChange: false,
Expand All @@ -103,6 +108,15 @@ const AddToListDialogInner: React.FC<AddToListDialogInnerProps> = ({
},
onSubmit: async (values) => {
if (resource) {
if (!(!POSTHOG?.api_key || POSTHOG.api_key.length < 1)) {
posthog.capture("lr_add_to_list", {
listType: listType,
resourceId: resource?.id,
readableId: resource?.readable_id,
platformCode: resource?.platform?.code,
resourceType: resource?.resource_type,
})
}
if (listType === ListType.LearningPath) {
const newParents = values.learning_paths.map((id) => parseInt(id))
await setLearningPathRelationships({
Expand Down
8 changes: 7 additions & 1 deletion frontends/mit-learn/src/pages/SearchPage/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { LearningResourceOfferor } from "api"
import { useOfferorsList } from "api/hooks/learningResources"
import { capitalize } from "ol-utilities"
import MetaTags from "@/page-components/MetaTags/MetaTags"
import { usePostHog } from "posthog-js/react"

const cssGradient = `
linear-gradient(
Expand Down Expand Up @@ -175,6 +176,8 @@ const useFacetManifest = (resourceCategory: string | null) => {
const SearchPage: React.FC = () => {
const [searchParams, setSearchParams] = useSearchParams()
const facetManifest = useFacetManifest(searchParams.get("resource_category"))
const posthog = usePostHog()
const { POSTHOG } = APP_SETTINGS

const setPage = useCallback(
(newPage: number) => {
Expand All @@ -191,8 +194,11 @@ const SearchPage: React.FC = () => {
[setSearchParams],
)
const onFacetsChange = useCallback(() => {
if (!(!POSTHOG?.api_key || POSTHOG.api_key.length < 1)) {
posthog.capture("search_update")
}
setPage(1)
}, [setPage])
}, [setPage, posthog, POSTHOG])

const {
params,
Expand Down
7 changes: 7 additions & 0 deletions frontends/ol-ckeditor/src/types/settings.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/* eslint-disable no-var */

export type PostHogSettings = {
api_key: string
timeout?: int
bootstrap_flags?: Record<string, string | boolean>
}

export declare global {
const APP_SETTINGS: {
EMBEDLY_KEY: string
Expand All @@ -9,5 +15,6 @@ export declare global {
PUBLIC_URL: string
SITE_NAME: string
CSRF_COOKIE_NAME: string
POSTHOG?: PostHogSettings
}
}
1 change: 1 addition & 0 deletions frontends/ol-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"material-ui-popup-state": "^5.1.0",
"ol-test-utilities": "0.0.0",
"ol-utilities": "0.0.0",
"posthog-js": "^1.165.0",
"react": "18.3.1",
"react-router": "^6.22.2",
"react-router-dom": "^6.22.2",
Expand Down
31 changes: 23 additions & 8 deletions frontends/ol-components/src/components/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RiSearch2Line, RiCloseLine } from "@remixicon/react"
import { Input, AdornmentButton } from "../Input/Input"
import type { InputProps } from "../Input/Input"
import styled from "@emotion/styled"
import { usePostHog } from "posthog-js/react"

const StyledInput = styled(Input)(({ theme }) => ({
boxShadow: "0px 8px 20px 0px rgba(120, 147, 172, 0.10)",
Expand Down Expand Up @@ -53,18 +54,32 @@ const muiInputProps = { "aria-label": "Search for" }

const SearchInput: React.FC<SearchInputProps> = (props) => {
const { onSubmit, value } = props
const handleSubmit = useCallback(() => {
const event = {
target: { value },
preventDefault: () => null,
}
onSubmit(event)
}, [onSubmit, value])
const posthog = usePostHog()
const { POSTHOG } = APP_SETTINGS

const handleSubmit = useCallback(
(
ev:
| React.SyntheticEvent<HTMLInputElement>
| React.SyntheticEvent<HTMLButtonElement, MouseEvent>,
isEnter: boolean = false,
) => {
const event = {
target: { value },
preventDefault: () => null,
}
if (!(!POSTHOG?.api_key || POSTHOG.api_key.length < 1)) {
posthog.capture("search_update", { isEnter: isEnter })
}
onSubmit(event)
},
[onSubmit, value, posthog, POSTHOG],
)
const onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement> =
useCallback(
(e) => {
if (e.key !== "Enter") return
handleSubmit()
handleSubmit(e, true)
},
[handleSubmit],
)
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.