Skip to content

Commit

Permalink
fix: fixed issue where env variables are not declared
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienne-deriv committed Jul 20, 2023
1 parent 67a4df4 commit 0faab1a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
21 changes: 4 additions & 17 deletions packages/analytics/src/rudderstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,12 @@ export class RudderStack {
has_initialized = false;
current_page = '';

constructor() {
this.init();
}

init() {
const is_production = process.env.CIRCLE_JOB === 'release_production';
const is_staging = process.env.CIRCLE_JOB === 'release_staging';

if (!is_production && !is_staging) return;

const RUDDERSTACK_KEY = is_production
? process.env.RUDDERSTACK_PRODUCTION_KEY
: process.env.RUDDERSTACK_STAGING_KEY;
const RUDDERSTACK_URL = process.env.RUDDERSTACK_URL;

if (RUDDERSTACK_KEY && RUDDERSTACK_URL) {
RudderAnalytics.load(RUDDERSTACK_KEY, RUDDERSTACK_URL);
init(rudderstack_key: string, rudderstack_url: string, callbackFn: () => any) {
if (!this.has_initialized) {
RudderAnalytics.load(rudderstack_key, rudderstack_url);
RudderAnalytics.ready(() => {
this.has_initialized = true;
callbackFn();
});
}
}
Expand Down
26 changes: 21 additions & 5 deletions packages/core/src/App/Containers/Layout/app-contents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import React from 'react';
import { withRouter } from 'react-router';
import WS from 'Services/ws-methods';
import { DesktopWrapper, MobileWrapper, ThemedScrollbars } from '@deriv/components';
import { CookieStorage, isMobile, TRACKING_STATUS_KEY, PlatformContext, platforms, routes } from '@deriv/shared';
import {
CookieStorage,
isProduction,
isMobile,
isStaging,
TRACKING_STATUS_KEY,
PlatformContext,
platforms,
routes,
} from '@deriv/shared';
import { RudderStack } from '@deriv/analytics';
import { connect } from 'Stores/connect';
import CookieBanner from '../../Components/Elements/CookieBanner/cookie-banner.jsx';
Expand Down Expand Up @@ -44,11 +53,18 @@ const AppContents = ({
if (response.error) return;
const user_id = response.authorize?.user_id;

if (is_logged_in && user_id) {
RudderStack.identifyEvent(user_id, {
language: getLanguage().toLowerCase() || 'en',
if (is_logged_in && user_id && (isStaging() || isProduction())) {
const rudderstack_key = isProduction()
? process.env.RUDDERSTACK_PRODUCTION_KEY
: process.env.RUDDERSTACK_STAGING_KEY;
const rudderstack_url = process.env.RUDDERSTACK_URL;

RudderStack.init(rudderstack_key, rudderstack_url, () => {
RudderStack.identifyEvent(user_id, {
language: getLanguage().toLowerCase() || 'en',
});
RudderStack.pageView(current_page);
});
RudderStack.pageView(current_page);
}
});

Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1648,12 +1648,20 @@ export default class ClientStore extends BaseStore {
if (this.loginid === authorize_response.authorize.loginid) {
BinarySocketGeneral.authorizeAccount(authorize_response);

// Client comes back from oauth and logs in
RudderStack.identifyEvent(this.user_id, {
language: getLanguage().toLowerCase(),
});
const current_page = window.location.hostname + window.location.pathname;
RudderStack.pageView(current_page);
if (isStaging() || isProduction()) {
const rudderstack_key = isProduction()
? process.env.RUDDERSTACK_PRODUCTION_KEY
: process.env.RUDDERSTACK_STAGING_KEY;
const rudderstack_url = process.env.RUDDERSTACK_URL;
RudderStack.init(rudderstack_key, rudderstack_url, () => {
// Client comes back from oauth and logs in
RudderStack.identifyEvent(this.user_id, {
language: getLanguage().toLowerCase(),
});
const current_page = window.location.hostname + window.location.pathname;
RudderStack.pageView(current_page);
});
}

await this.root_store.gtm.pushDataLayer({
event: 'login',
Expand Down

0 comments on commit 0faab1a

Please sign in to comment.