Skip to content

Commit

Permalink
Merge pull request #3580 from omnivore-app/feature/replace-segment-wi…
Browse files Browse the repository at this point in the history
…th-posthog

replace segment with posthog
  • Loading branch information
sywhb authored Feb 26, 2024
2 parents a969cad + 0369a39 commit befb479
Show file tree
Hide file tree
Showing 32 changed files with 181 additions and 219 deletions.
2 changes: 1 addition & 1 deletion packages/api/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ GCS_UPLOAD_BUCKET=
GCS_UPLOAD_SA_KEY_FILE_PATH=
GCS_UPLOAD_PRIVATE_BUCKET=
TWITTER_BEARER_TOKEN=
SEGMENT_WRITE_KEY='test'
POSTHOG_API_KEY='test'
PUBSUB_VERIFICATION_TOKEN='123456'
CONTENT_FETCH_URL=http://localhost:9090/
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@sentry/node": "^5.26.0",
"@sentry/tracing": "^7.9.0",
"addressparser": "^1.0.1",
"analytics-node": "^6.0.0",
"apollo-datasource": "^3.3.1",
"apollo-server-express": "^3.6.3",
"axios": "^0.27.2",
Expand Down Expand Up @@ -88,6 +87,7 @@
"oauth": "^0.10.0",
"pg": "^8.3.3",
"postgrator": "^4.2.0",
"posthog-node": "^3.6.3",
"private-ip": "^2.3.3",
"prom-client": "^15.1.0",
"rss-parser": "^3.13.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/api/src/resolvers/api_key/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const generateApiKeyResolver = authorized<
expiresAt: exp,
})

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'api_key_generated',
properties: {
name,
Expand Down Expand Up @@ -92,8 +92,8 @@ export const revokeApiKeyResolver = authorized<

const deletedApiKey = await apiRepo.remove(apiKey)

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'api_key_revoked',
properties: {
id,
Expand Down
30 changes: 15 additions & 15 deletions packages/api/src/resolvers/article/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ export const createArticleResolver = authorized<
},
{ log, uid, pubsub }
) => {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'link_saved',
properties: {
url,
Expand Down Expand Up @@ -491,7 +491,7 @@ export const getArticleResolver = authorized<
// source: 'resolver',
// resolver: 'setShareArticleResolver',
// articleId: article.id,
// userId: uid,
// distinctId: uid,
// },
// })

Expand Down Expand Up @@ -535,8 +535,8 @@ export const setBookmarkArticleResolver = authorized<
// delete the item and its metadata
const deletedLibraryItem = await softDeleteLibraryItem(articleID, uid, pubsub)

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'link_removed',
properties: {
id: articleID,
Expand Down Expand Up @@ -833,8 +833,8 @@ export const bulkActionResolver = authorized<
{ uid, log }
) => {
try {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'BulkAction',
properties: {
env: env.server.apiEnv,
Expand Down Expand Up @@ -891,8 +891,8 @@ export const setFavoriteArticleResolver = authorized<
MutationSetFavoriteArticleArgs
>(async (_, { id }, { uid, log }) => {
try {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'setFavoriteArticle',
properties: {
env: env.server.apiEnv,
Expand Down Expand Up @@ -928,8 +928,8 @@ export const moveToFolderResolver = authorized<
MoveToFolderError,
MutationMoveToFolderArgs
>(async (_, { id, folder }, { authTrx, log, pubsub, uid }) => {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'move_to_folder',
properties: {
id,
Expand Down Expand Up @@ -1002,8 +1002,8 @@ export const fetchContentResolver = authorized<
FetchContentError,
MutationFetchContentArgs
>(async (_, { id }, { authTrx, uid, log, pubsub }) => {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'fetch_content',
properties: {
id,
Expand Down Expand Up @@ -1052,8 +1052,8 @@ export const emptyTrashResolver = authorized<
EmptyTrashSuccess,
EmptyTrashError
>(async (_, __, { uid }) => {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'empty_trash',
})

Expand Down
7 changes: 3 additions & 4 deletions packages/api/src/resolvers/article_saving_request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ import {
findLibraryItemByUrl,
} from '../../services/library_item'
import { analytics } from '../../utils/analytics'
import { authorized } from '../../utils/gql-utils'
import {
cleanUrl,
isParsingTimeout,
libraryItemToArticleSavingRequest,
} from '../../utils/helpers'
import { authorized } from '../../utils/gql-utils'

import { isErrorWithCode } from '../user'

export const createArticleSavingRequestResolver = authorized<
CreateArticleSavingRequestSuccess,
CreateArticleSavingRequestError,
MutationCreateArticleSavingRequestArgs
>(async (_, { input: { url } }, { uid, pubsub, log }) => {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'link_saved',
properties: {
url: url,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/resolvers/filters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ export const moveFilterResolver = authorized<
}
}

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'filter_moved',
properties: {
filterId,
Expand Down
8 changes: 4 additions & 4 deletions packages/api/src/resolvers/highlight/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const createHighlightResolver = authorized<
pubsub
)

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'highlight_created',
properties: {
libraryItemId: input.articleId,
Expand Down Expand Up @@ -143,8 +143,8 @@ export const mergeHighlightResolver = authorized<
pubsub
)

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'highlight_created',
properties: {
libraryItemId: input.articleId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const uploadImportFileResolver = authorized<
}
}

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'upload_import_file',
properties: {
type,
Expand Down
12 changes: 6 additions & 6 deletions packages/api/src/resolvers/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export const setIntegrationResolver = authorized<
integration.taskName = null
}

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'integration_set',
properties: {
id: integrationToSave.id,
Expand Down Expand Up @@ -182,8 +182,8 @@ export const deleteIntegrationResolver = authorized<
const deletedIntegration = await removeIntegration(integration, uid)
deletedIntegration.id = id

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'integration_delete',
properties: {
integrationId: deletedIntegration.id,
Expand Down Expand Up @@ -238,8 +238,8 @@ export const importFromIntegrationResolver = authorized<
// update task name in integration
await updateIntegration(integration.id, { taskName }, uid)

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'integration_import',
properties: {
integrationId,
Expand Down
26 changes: 13 additions & 13 deletions packages/api/src/resolvers/labels/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export const labelsResolver = authorized<LabelsSuccess, LabelsError>(
})
})

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'labels',
properties: {
env: env.server.apiEnv,
$set: {
$set_once: {
email: user.email,
username: user.profile.username,
},
Expand Down Expand Up @@ -95,8 +95,8 @@ export const createLabelResolver = authorized<
return tx.withRepository(labelRepository).createLabel(input, uid)
})

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'label_created',
properties: {
...input,
Expand Down Expand Up @@ -128,8 +128,8 @@ export const deleteLabelResolver = authorized<
}
}

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'label_deleted',
properties: {
labelId,
Expand Down Expand Up @@ -207,8 +207,8 @@ export const setLabelsResolver = authorized<
// save labels in the library item
await saveLabelsInLibraryItem(labelsSet, pageId, uid, labelSource, pubsub)

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'labels_set',
properties: {
pageId,
Expand Down Expand Up @@ -282,8 +282,8 @@ export const setLabelsForHighlightResolver = authorized<
// save labels in the highlight
await saveLabelsInHighlight(labelsSet, input.highlightId, uid, pubsub)

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'labels_set_for_highlight',
properties: {
highlightId,
Expand Down Expand Up @@ -374,8 +374,8 @@ export const moveLabelResolver = authorized<
}
}

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'label_moved',
properties: {
labelId,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/resolvers/links/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export const setLinkArchivedResolver = authorized<
event = 'link_unarchived'
}

analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event,
properties: {
env: env.server.apiEnv,
Expand Down
16 changes: 8 additions & 8 deletions packages/api/src/resolvers/newsletters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export const createNewsletterEmailResolver = authorized<
CreateNewsletterEmailSuccessPartial,
CreateNewsletterEmailError,
MutationCreateNewsletterEmailArgs
>(async (_parent, { input }, { claims, log }) => {
>(async (_parent, { input }, { uid, log }) => {
log.info('createNewsletterEmailResolver')
analytics.track({
userId: claims.uid,
analytics.capture({
distinctId: uid,
event: 'newsletter_email_address_created',
properties: {
env: env.server.apiEnv,
Expand All @@ -52,7 +52,7 @@ export const createNewsletterEmailResolver = authorized<

try {
const newsletterEmail = await createNewsletterEmail(
claims.uid,
uid,
undefined,
input?.folder || DEFAULT_NEWSLETTER_FOLDER,
input?.name || undefined,
Expand Down Expand Up @@ -103,8 +103,8 @@ export const deleteNewsletterEmailResolver = authorized<
DeleteNewsletterEmailError,
MutationDeleteNewsletterEmailArgs
>(async (_parent, args, { uid, log }) => {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'newsletter_email_address_deleted',
properties: {
env: env.server.apiEnv,
Expand Down Expand Up @@ -158,8 +158,8 @@ export const updateNewsletterEmailResolver = authorized<
UpdateNewsletterEmailError,
MutationUpdateNewsletterEmailArgs
>(async (_parent, { input }, { uid, log }) => {
analytics.track({
userId: uid,
analytics.capture({
distinctId: uid,
event: 'newsletter_email_updated',
properties: {
env: env.server.apiEnv,
Expand Down
Loading

0 comments on commit befb479

Please sign in to comment.