Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

[C-843] Native analytics sagas#1734

Merged
sliptype merged 10 commits into
mainfrom
sk-c-843-native-analytics-sagas
Aug 18, 2022
Merged

[C-843] Native analytics sagas#1734
sliptype merged 10 commits into
mainfrom
sk-c-843-native-analytics-sagas

Conversation

@sliptype

Copy link
Copy Markdown
Contributor

Description

May be easiest to review by commit bc of all the path changes

  • Move analytics actions and sagas into web common
  • Add analytics object into storeContext
  • Add webAnalyticsSagas that handle page view tracking (still emitting messages to mobile for now)
  • Add common analytics sagas to mobile (aren't being used yet)
  • Move mobile utils/analytics to services/analytics

Dragons

Had to make the analytics interface consistent between web and mobile to use in the storeContext. Decided to conform to

{
  eventName: string
  properties?: Record<string, any>
}

because mobile was already using that format everywhere and calling track directly, whereas web was mostly using the useRecord hook so the change only needed to happen in one place. I added an issue to make the readdress the analytics implementation and make it consistent across the board: https://linear.app/audius/issue/C-848/make-analytics-implementation-consistent-across-web-and-mobile

How Has This Been Tested?

Tested analytics on web and mobile including page views and payloads

How will this change be monitored?

For features that are critical or could fail silently please describe the monitoring/alerting being added.

Feature Flags

Are all new features properly feature flagged? Describe added feature flags.

@dylanjeffers dylanjeffers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all makes good sense, nice job

PushNotifications.setWebRef(webRef)
}, [webRef])

useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

import { Linking, Pressable } from 'react-native'

import { ToastContext } from 'app/components/toast/ToastContext'
import { make, track } from 'app/services/analytics'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under services makes much more sense

const sagas = [
// config
...backendSagas(),
...analyticsSagas(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! so we want to have these around for now then?

@sliptype sliptype Aug 18, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they aren't touching any state and are very small so I think it's ok to have them

recordAnalytics: (
event: string,
properties?: Record<string, any>,
event: { eventName: string; properties?: Record<string, any> },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to use Record<string, unknown> i think that is technically the best version of "any object"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, can actually use AnalyticsEvent here

selectedAs: 'primary',
reason
recordAnalytics({
eventName: Name.CREATOR_NODE_SELECTION,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow epic job changing all these

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! idk if this is the final interface we should use but updating web was the quickest route

analytics.track,
{
eventName,
properties: omit(properties, 'type')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome stuff, so do we just want to omit type in the destructuring?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That causes the linter to complain about type not being used so I opted for this instead

track: (event: AnalyticsEvent, callback?: () => void) => Promise<void>
identify: (
handle: string,
traits?: Record<string, any>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here just regarding <string, any> vs <string, unknown>


import { useModalState } from 'common/hooks/useModalState'
import { getPlaylistLibrary } from 'common/store/account/selectors'
import { make, useRecord } from 'common/store/analytics/actions'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it makes sense to have useRecord in actions? i guess it's a special action? and looks like that's what was there before anyway so nvm

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't make sense, we can address in the other analytics issue I created

const audiusBackendInstance = yield* getContext('audiusBackendInstance')
yield* call(waitForBackendSetup)
yield* call(audiusBackendInstance.markAllNotificationAsViewed)
if (NATIVE_MOBILE) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i forgot, we still want this yeah?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Yup, I'm getting too eager to remove stuff

source
})
record(
make(Name.REWARDS_CLAIM_FINISH_COGNITO_FLOW, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering if make should just be a part of record at some point?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely think so, can address as part of the other issue

@audius-infra

Copy link
Copy Markdown
Collaborator

Preview this change https://demo.audius.co/sk-c-843-native-analytics-sagas

@audius-infra

Copy link
Copy Markdown
Collaborator

Preview this change https://demo.audius.co/sk-c-843-native-analytics-sagas

@sliptype sliptype merged commit 1a98edb into main Aug 18, 2022
@sliptype sliptype deleted the sk-c-843-native-analytics-sagas branch August 18, 2022 16:30
@sliptype sliptype mentioned this pull request Aug 18, 2022
@AudiusProject AudiusProject deleted a comment from linear Bot Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants