Skip to content

Commit

Permalink
[DTRA] henry/dtra-535/hotjar-events-for-trade-types (binary-com#12078)
Browse files Browse the repository at this point in the history
* fix: initial commit

* fix: add hotjar events for contract type selection and trade placed

* fix: move event tracker to contract-type-widget and allow for testing on staging

* fix: resolve comments
  • Loading branch information
henry-deriv committed Dec 12, 2023
1 parent 84dbad8 commit a204aea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/Utils/Hotjar/index.ts
@@ -1,11 +1,11 @@
import { epochToMoment, toMoment } from '@deriv/shared';
import { TCoreStores } from '@deriv/stores/types';

const isProduction = process.env.NODE_ENV === 'production';
const isProductionOrStaging = process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging';

const initHotjar = (client: TCoreStores['client']) => {
// To initialize only on licensed domains.
if (!isProduction) return;
// To initialize only on staging and production links
if (!isProductionOrStaging) return;

/**
* Inject: External Script - Hotjar
Expand Down
Expand Up @@ -90,6 +90,7 @@ const ContractTypeWidget = observer(

onChange({ target: { name, value: clicked_item.value } });

if ((window as any).hj) (window as any).hj('event', `selected_${value}_contract_type`);
if (subform_name === 'trade_type') {
Analytics.trackEvent('ce_trade_types_form', {
action: 'choose_trade_type',
Expand Down
3 changes: 3 additions & 0 deletions packages/trader/src/Stores/Modules/Trading/trade-store.ts
Expand Up @@ -908,6 +908,9 @@ export default class TradeStore extends BaseStore {
const is_digit_contract = isDigitContractType(category?.toUpperCase() ?? '');
const is_multiplier = isMultiplierContract(category);
const contract_type = category?.toUpperCase();

if ((window as any).hj) (window as any).hj('event', `placed_${category}_trade`);

this.root_store.contract_trade.addContract({
contract_id,
start_time,
Expand Down

0 comments on commit a204aea

Please sign in to comment.