* Merge main * MarketLinks: add key to map * Merge stashed changes * fix callback usage to fulfill success/error cbs * Add Abacus analytics class * Bump Abacus 0.4.27, Update cancelOrder to use Abacus * Cancel order loading states * Use latestOrderChanged to determine whether an order has been committed * nits * restore uncommittedOrderClientIds * bump abacus@0.5.0 * fix for handling null testMarket
37 lines
885 B
TypeScript
37 lines
885 B
TypeScript
import type {
|
|
AnalyticsUserProperty,
|
|
AnalyticsUserPropertyValue,
|
|
AnalyticsEvent,
|
|
AnalyticsEventData,
|
|
} from '@/constants/analytics';
|
|
|
|
const DEBUG_ANALYTICS = false;
|
|
|
|
export const identify = <T extends AnalyticsUserProperty>(
|
|
property: T,
|
|
propertyValue: AnalyticsUserPropertyValue<T>
|
|
) => {
|
|
if (DEBUG_ANALYTICS) {
|
|
console.log(`[Analytics:Identify] ${property}`, propertyValue);
|
|
}
|
|
const customEvent = new CustomEvent('dydx:identify', {
|
|
detail: { property, propertyValue },
|
|
});
|
|
|
|
globalThis.dispatchEvent(customEvent);
|
|
};
|
|
|
|
export const track = <T extends AnalyticsEvent>(
|
|
eventType: T,
|
|
eventData?: AnalyticsEventData<T>
|
|
) => {
|
|
if (DEBUG_ANALYTICS) {
|
|
console.log(`[Analytics] ${eventType}`, eventData);
|
|
}
|
|
const customEvent = new CustomEvent('dydx:track', {
|
|
detail: { eventType, eventData },
|
|
});
|
|
|
|
globalThis.dispatchEvent(customEvent);
|
|
};
|