Skip to content

Commit 66b6755

Browse files
authored
Merge pull request #148 from CodeClimbersIO/blocked-sites-event-posthog
Blocked webs/apps event Posthog
2 parents 97d0494 + d8f4f31 commit 66b6755

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ Ebb uses your window, mouse and keyboard activity to track your workflow habits.
3131
The monitoring service is a Rust application that runs on your computer and is responsible for recording your activities. It is designed to be run as a background service and will not interfere with your workflow. Makes use of the os-monitor crate to monitor your activities and then record them to the database on your device.
3232

3333
# [Monitor](https://github.com/CodeClimbersIO/os-monitor)
34-
3534
The monitor is a Rust application that runs on your computer and is responsible for monitoring your activities. It is specifically responsible for monitoring (but not recording) your window, mouse and keyboard activity.

src/api/ebbApi/blockingPreferenceApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ const getWorkflowBlockedApps = async (workflowId: string): Promise<BlockingAppCo
121121
const getDefaultSearchOptions = async (): Promise<SearchOption[]> => {
122122
const defaultCategoryNames = ['social media', 'entertainment']
123123
const allCategoryTags = await TagRepo.getTagsByType('category')
124-
const defaultTags = allCategoryTags.filter((tag: Tag) =>
124+
const defaultTags = allCategoryTags.filter((tag: Tag) =>
125125
defaultCategoryNames.includes(tag.name)
126126
)
127127
const defaultTagIds = defaultTags.map((tag: Tag) => tag.id).filter((id): id is string => !!id)
128-
128+
129129
let defaultSearchOptions: SearchOption[] = []
130130
if (defaultTagIds.length > 0) {
131131
const categoriesWithCounts = await TagRepo.getCategoriesWithAppCounts(defaultTagIds)
132132
defaultSearchOptions = categoriesWithCounts.map((catInfo: TagWithAppCount): SearchOption => ({
133133
type: 'category',
134-
tag: catInfo,
134+
tag: catInfo,
135135
category: catInfo.name as AppCategory,
136136
count: catInfo.count
137137
}))

src/hooks/useNotificationListener.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ import { useNavigate } from 'react-router-dom'
77
import { SmartSessionApi } from '@/api/ebbApi/smartSessionApi'
88
import { useFlowTimer } from '@/lib/stores/flowTimer'
99
import { FlowSessionApi } from '@/api/ebbApi/flowSessionApi'
10+
import { AnalyticsService } from '@/lib/analytics'
11+
12+
interface BlockedApp {
13+
app_name: string
14+
app_external_id: string
15+
}
16+
17+
const trackBlockedApps = (blockedApps: BlockedApp[], workflowId?: string, workflowName?: string) => {
18+
blockedApps.forEach((app) => {
19+
// For websites, use app_external_id (the URL), for apps use app_name
20+
const blockedName = app.app_external_id || app.app_name
21+
22+
AnalyticsService.trackEvent('app_or_website_block_attempt', {
23+
blocked_item_name: blockedName,
24+
workflow_id: workflowId,
25+
workflow_name: workflowName,
26+
})
27+
})
28+
}
1029

1130
export const useNotificationListener = () => {
1231
const navigate = useNavigate()
@@ -55,17 +74,26 @@ export const useNotificationListener = () => {
5574
window.dispatchEvent(new Event('end-session'))
5675
})
5776
})
58-
unlistenAppBlocked = await listen('on-app-blocked', async () => {
77+
unlistenAppBlocked = await listen('on-app-blocked', async (event: { payload: { blocked_apps: BlockedApp[] } }) => {
5978
info('App: app blocked')
6079
EbbWorker.debounceWork(async () => {
6180
try {
6281
const session = await FlowSessionApi.getInProgressFlowSessionWithWorkflow()
6382
const isHardMode = session?.workflow_json?.settings.difficulty === 'hard'
83+
6484
if (isHardMode) {
6585
await invoke('show_notification', { notificationType: 'blocked-app-hard' })
6686
} else {
6787
await invoke('show_notification', { notificationType: 'blocked-app' })
6888
}
89+
90+
if (event.payload?.blocked_apps) {
91+
trackBlockedApps(
92+
event.payload.blocked_apps,
93+
session?.workflow_id,
94+
session?.workflow_json?.name
95+
)
96+
}
6997
} catch (error) {
7098
console.error(`Error getting in progress flow session with workflow: ${error}`, error)
7199
}

src/hooks/usePermissions.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,29 @@ import { useAuth } from './useAuth'
33
import { defaultPermissions } from '@/api/ebbApi/licenseApi'
44
import { usePermissionsStore } from '@/lib/stores/permissionsStore'
55
import { useEffect } from 'react'
6+
import { isDev } from '@/lib/utils/environment.util'
7+
8+
const devPermissions = {
9+
canUseHardDifficulty: true,
10+
canUseAllowList: true,
11+
canUseMultipleProfiles: true,
12+
canUseMultipleDevices: true,
13+
canUseSmartFocus: true,
14+
canUseSlackIntegration: true,
15+
canScheduleSessions: true,
16+
hasProAccess: true,
17+
}
618

719
export const usePermissions = () => {
820
const { user } = useAuth()
921
const { data: licenseData } = useLicenseWithDevices(user?.id || null)
1022
const setPermissions = usePermissionsStore((state) => state.setPermissions)
1123

12-
const permissions = licenseData?.permissions || defaultPermissions
24+
// In dev mode, grant all pro permissions
25+
const isDevMode = isDev()
26+
const permissions = isDevMode
27+
? devPermissions
28+
: (licenseData?.permissions || defaultPermissions)
1329

1430
// Sync to store whenever permissions change
1531
useEffect(() => {

src/lib/analytics.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export type AnalyticsEvent =
135135
| 'activity_history_delete_all_clicked'
136136
| 'activity_history_page_changed'
137137

138+
// Blocking Events
139+
| 'app_or_website_block_attempt'
140+
138141
export interface AnalyticsEventProperties {
139142
// Focus session properties
140143
difficulty?: 'easy' | 'medium' | 'hard'
@@ -157,6 +160,9 @@ export interface AnalyticsEventProperties {
157160

158161
// Billing properties
159162
days_remaining?: number
163+
164+
// Block attempt properties
165+
blocked_item_name?: string
160166
}
161167

162168
const trackEvent = (

0 commit comments

Comments
 (0)