Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adrienne / Rudderstack integration #9013

Conversation

adrienne-deriv
Copy link
Contributor

@adrienne-deriv adrienne-deriv commented Jun 14, 2023

Changes:

  • Removed rudderstack-store from root store
  • Added rudderstack integration to shared package

Please provide a summary of the change.

Screenshots:

Please provide some screenshots of the change.

@vercel
Copy link

vercel bot commented Jun 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
deriv-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2023 9:48am

@github-actions
Copy link
Contributor

github-actions bot commented Jun 14, 2023

A production App ID was automatically generated for this PR. (log)

Click here to copy & paste above information.
- **PR**: [https://github.com/binary-com/deriv-app/pull/9013](https://github.com/binary-com/deriv-app/pull/9013)
- **URLs**:
    - **w/ App ID + Server**: https://deriv-app-git-fork-adrienne-deriv-rudderstack-integration-hook.binary.sx?qa_server=red.binaryws.com&app_id=24096
    - **Original**: https://deriv-app-git-fork-adrienne-deriv-rudderstack-integration-hook.binary.sx
- **App ID**: `24096`

@github-actions
Copy link
Contributor

github-actions bot commented Jun 14, 2023

🚨 Lighthouse report for the changes in this PR:

Category Score
🔺 Performance 20
🟧 Accessibility 75
🟢 Best practices 92
🟧 SEO 85
🟢 PWA 90

Lighthouse ran with https://deriv-app-git-fork-adrienne-deriv-rudderstack-integration-hook.binary.sx/

Copy link
Contributor

@farzin-deriv farzin-deriv left a comment

Choose a reason for hiding this comment

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

Nice work man 🚀

I think we can go with a simpler implementation, We basically just want to add types around RudderStack SDK 🤔 What do you think? 🤔

class RudderStack {
    constructor() {
        this.init();
    }

    init = () => {
        // Abort if RudderStack key or url is not set in .env
        if (!process.env.RUDDERSTACK_KEY || !process.env.RUDDERSTACK_URL) return;

        rudderanalytics.load(process.env.RUDDERSTACK_KEY, process.env.RUDDERSTACK_URL);
    };

    identify = (user_id: string, payload: TEvents['identify']) => rudderanalytics.identify(user_id, payload);

    track = <T extends keyof TEvents>(event: T, payload: TPayload[T]) => rudderanalytics.track(event, payload);

    page = (name: string) => rudderanalytics.page('Deriv App', name);

    reset = () => rudderanalytics.reset();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 🚀

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 🚀

Comment on lines 125 to 127
pageView() {
const current_page = window.location.hostname + window.location.pathname;

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pageView() {
const current_page = window.location.hostname + window.location.pathname;
pageView(current_page: string) {

@adrienne-deriv Let's make it prop instead of using window.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adrienne-deriv This file shouldn't be in the changes 👀

@@ -1,4 +1,5 @@
export * from './services';
export * from './utils/analytics';
Copy link
Contributor

Choose a reason for hiding this comment

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

@adrienne-deriv I would still recommend creating a new package like @deriv/analytics and move this implementation there instead of @deriv/shared 👀

cc: @yashim-deriv

Copy link
Contributor

Choose a reason for hiding this comment

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

Absolutely. I think this would be a great thing to abstract out, as we will surely use it in multiple projects as we abstract out the projects.

current_page = '';

constructor() {
const write_key = isProduction() ? process.env.RUDDERSTACK_PRODUCTION_KEY : process.env.RUDDERSTACK_STAGING_KEY;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const write_key = isProduction() ? process.env.RUDDERSTACK_PRODUCTION_KEY : process.env.RUDDERSTACK_STAGING_KEY;
const write_key = process.env.RUDDERSTACK_KEY;

This should be handled in the CI, We should expose the different environment variables there 🤔

cc: @ali-hosseini-deriv @yashim-deriv

Copy link
Member

Choose a reason for hiding this comment

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

with our current circleci setup this is not possible.
what we can do is to decide based on the circle ci job name.
I believe @adrienne-deriv is implementing it now in that way.

Comment on lines 147 to 150
track<EventType extends keyof RSEvents, EventPayload extends RSEvents[EventType]>(
event_type: EventType,
payload: EventPayload
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
track<EventType extends keyof RSEvents, EventPayload extends RSEvents[EventType]>(
event_type: EventType,
payload: EventPayload
) {
track<T extends keyof TEvents>(event: T, payload: TPayload[T]) {

@adrienne-deriv Let's name things simpler 🙇🏻

error_message?: string;
};

type TradeTypesFormAction =
Copy link
Contributor

Choose a reason for hiding this comment

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

@adrienne-deriv Let's do some type improvements together when you are free if you like 🙇🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeaah I need some feedback on these types 😅

rudderstack.identifyEvent(user_id, {
language: getLanguage().toLowerCase() || 'en',
});
rudderstack.pageView();
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to call pageView() again? because It's being called inside identyfyEvent 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

and correct me if I'm wrong, we are calling identyfyEvent inside client-store after user is logged in. so here when we call it again, it's not going to do anything because has_initialized is already set to true , right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I've added rudderstack.reset() when the user logs out, so this resets the state has_identified to false

Copy link
Contributor Author

@adrienne-deriv adrienne-deriv Jun 15, 2023

Choose a reason for hiding this comment

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

Actually I'll remove the pageView call inside identifyEvent, it should be called separately

Copy link
Contributor

@shayan-deriv shayan-deriv left a comment

Choose a reason for hiding this comment

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

One more thing. I agree with Farzin and Mark about abstracting these things in a separate package so It can be used across all of our projects.

@@ -0,0 +1,6373 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this package-lock and run npm run bootstrap:dev in the root 🙏

farzin-deriv
farzin-deriv previously approved these changes Jun 23, 2023
Copy link
Contributor

@maryia-deriv maryia-deriv left a comment

Choose a reason for hiding this comment

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

👍🏻

jim-deriv
jim-deriv previously approved these changes Jun 26, 2023
@coveralls
Copy link

coveralls commented Jul 5, 2023

Coverage Status

coverage: 8.902% (+0.03%) from 8.875% when pulling 212bb46 on adrienne-deriv:rudderstack-integration-hook into f48ed0d on binary-com:master.

}

init() {
const isProduction = process.env.CIRCLE_JOB === 'release_production';
Copy link
Member

Choose a reason for hiding this comment

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

please write it in a way to make sure CIRCLE_JOB is either production or staging otherwise you need to skip it.
lets say on test links or localhost, we need to exclude them, right?

Copy link
Contributor

@jim-deriv jim-deriv left a comment

Choose a reason for hiding this comment

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

LGTM

@sonarcloud
Copy link

sonarcloud bot commented Jul 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
1.8% 1.8% Duplication

@ali-hosseini-deriv
Copy link
Member

✨ PR has been merged by Paimon the Release Bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants