Skip to content

Commit

Permalink
Merge pull request #118 from deriv-com/habib/setup-rudderstack
Browse files Browse the repository at this point in the history
Setup Rudderstack config
  • Loading branch information
habib-deriv authored Apr 22, 2024
2 parents a7d3a95 + 037ff35 commit 285f655
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ jobs:
project_name: "traders-hub"
branch_name: staging
output_dir: dist
env:
RUDDERSTACK_KEY: ${{ vars.VITE_RUDDERSTACK_KEY }}
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
project_name: "traders-hub"
branch_name: "pr-${{github.event.number}}"
output_dir: dist
env:
RUDDERSTACK_KEY: ${{ vars.VITE_RUDDERSTACK_KEY }}

- name: "Generate preview link comment"
uses: "deriv-com/shared-actions/.github/actions/post_preview_link_comment@v1"
Expand Down
23 changes: 19 additions & 4 deletions package-lock.json

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

53 changes: 46 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,72 @@
import React from 'react';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom/client';

import { AppDataProvider } from '@deriv-com/api-hooks';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Analytics } from '@deriv-com/analytics';
import { AppDataProvider, useWebsiteStatus } from '@deriv-com/api-hooks';
import { useDevice } from '@deriv-com/ui';
import { WebSocketUtils } from '@deriv-com/utils';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

import { CFDProvider, RealAccountCreationProvider, UIProvider } from '@/providers';
import { startInitPerformanceTimers } from '@/utils';

import { Header } from './components/Header/Header.tsx';
import App from './App.tsx';
import { Header } from './components/Header/Header';
import { useActiveDerivTradingAccount } from './hooks/useActiveDerivTradingAccount';
import App from './App';

import './index.css';

const queryClient = new QueryClient();

// function to start the timer for login/signup/redirect
const AnalyticsConfigurator = () => {
const { data: activeTradingAccount } = useActiveDerivTradingAccount();
const { data: websiteStatusData } = useWebsiteStatus();
const { isDesktop, isMobile, isTablet } = useDevice();
const { getAppId } = WebSocketUtils;

useEffect(() => {
if (websiteStatusData?.clients_country) {
const accountType = activeTradingAccount?.is_virtual ? 'demo' : 'real';
const clientCountry = websiteStatusData.clients_country;

if (import.meta.env.VITE_RUDDERSTACK_KEY) {
const config = {
rudderstackKey: import.meta.env.VITE_RUDDERSTACK_KEY,
};
Analytics.initialise(config);
const attributes = {
account_type: accountType,
app_id: getAppId(),
device_type:
(isDesktop && 'Desktop') || (isMobile && 'Mobile') || (isTablet && 'Tablet') || 'Mobile',
device_language: navigator.language || 'en-EN',
user_language: 'en-EN',
country: clientCountry,
};
Analytics.setAttributes(attributes);
}
}
}, [activeTradingAccount, websiteStatusData]);

Check warning on line 51 in src/main.tsx

View workflow job for this annotation

GitHub Actions / build_to_cloudflare_pages

React Hook useEffect has missing dependencies: 'getAppId', 'isDesktop', 'isMobile', and 'isTablet'. Either include them or remove the dependency array

return null;
};

const container = document.getElementById('root');
const root = container ? ReactDOM.createRoot(container) : null;
startInitPerformanceTimers();

ReactDOM.createRoot(document.getElementById('root')!).render(
root?.render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<AppDataProvider>
<UIProvider>
<CFDProvider>
<RealAccountCreationProvider>
{/* Temporary Header */}
<Header />
<App />
<AnalyticsConfigurator />
</RealAccountCreationProvider>
</CFDProvider>
</UIProvider>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"types": ["@testing-library/jest-dom"],
"types": ["node", "@testing-library/jest-dom"],
"paths": {
"@/*": ["./src/*"],
"@cfd/*": ["./src/cfd/*"]
Expand Down

0 comments on commit 285f655

Please sign in to comment.