From aeb0e37caa5b4a80c1961a5f084711919cb81b0a Mon Sep 17 00:00:00 2001 From: jenniw Date: Mon, 12 Aug 2024 13:10:13 -0400 Subject: [PATCH] move to outer app.js --- ecommerce/views/v0/__init__.py | 1 + .../public/src/components/NotificationContainer.js | 14 +------------- frontend/public/src/containers/App.js | 13 +++++++++++++ frontend/public/src/lib/notificationsApi.js | 7 +++++-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ecommerce/views/v0/__init__.py b/ecommerce/views/v0/__init__.py index a263cfcefb..a0b5287782 100644 --- a/ecommerce/views/v0/__init__.py +++ b/ecommerce/views/v0/__init__.py @@ -573,6 +573,7 @@ def post_checkout_redirect(self, order_state, order, request): { "type": USER_MSG_TYPE_PAYMENT_ACCEPTED, "run": order.lines.first().purchased_object.course.title, + "order": order.reference_number, }, ) else: diff --git a/frontend/public/src/components/NotificationContainer.js b/frontend/public/src/components/NotificationContainer.js index 4faf6cefe6..e1a0136808 100644 --- a/frontend/public/src/components/NotificationContainer.js +++ b/frontend/public/src/components/NotificationContainer.js @@ -13,13 +13,10 @@ import { newSetWithout, timeoutPromise } from "../lib/util" -import { determineUserActionForGoogleAnalytics, getNotificationAlertProps } from "../lib/notificationsApi" +import { getNotificationAlertProps } from "../lib/notificationsApi" import { notificationTypeMap, TextNotification } from "./notifications" -import { checkFeatureFlag } from "../lib/util" -import { sendGAEcommerceEvent } from "../util/gaUtils" import type { UserNotificationMapping } from "../reducers/notifications" -import {GOOGLE_ANALYTICS_EVENT_TYPE} from "../constants"; const DEFAULT_REMOVE_DELAY_MS = 1000 @@ -59,17 +56,8 @@ export class NotificationContainer extends React.Component { render() { const { userNotifications } = this.props - const { currentUser } = this.props const { hiddenNotifications } = this.state - const ga_feature_flag = checkFeatureFlag("mitxonline-4099-dedp-google-analytics", currentUser) - if (ga_feature_flag) { - let gaEcommerceEventType = determineUserActionForGoogleAnalytics(currentUser) - if (gaEcommerceEventType === GOOGLE_ANALYTICS_EVENT_TYPE["GA_PURCHASE"]) { - sendGAEcommerceEvent(gaEcommerceEventType, event) - } - } - return (
{Object.keys(userNotifications).map((notificationKey, i) => { diff --git a/frontend/public/src/containers/App.js b/frontend/public/src/containers/App.js index 1ee80bf5e6..01fd73cddc 100644 --- a/frontend/public/src/containers/App.js +++ b/frontend/public/src/containers/App.js @@ -10,6 +10,7 @@ import urljoin from "url-join" import users, { currentUserSelector } from "../lib/queries/users" import { routes } from "../lib/urls" import { + determineUserActionForGoogleAnalytics, getStoredUserMessage, removeStoredUserMessage } from "../lib/notificationsApi" @@ -32,6 +33,9 @@ import CatalogPage from "./pages/CatalogPage" import type { Match, Location } from "react-router" import type { CurrentUser } from "../flow/authTypes" +import {checkFeatureFlag} from "../lib/util"; +import {GOOGLE_ANALYTICS_EVENT_TYPE} from "../constants"; +import {sendGAEcommerceEvent} from "../util/gaUtils"; type Props = { match: Match, @@ -45,6 +49,15 @@ export class App extends React.Component { const { addUserNotification } = this.props const { currentUser } = this.props + const ga_feature_flag = checkFeatureFlag("mitxonline-4099-dedp-google-analytics", currentUser) + if (ga_feature_flag) { + let gaEcommerceEventObject = determineUserActionForGoogleAnalytics(currentUser) + if (gaEcommerceEventObject.action === GOOGLE_ANALYTICS_EVENT_TYPE["GA_PURCHASE"]) { + let event = gaEcommerceEventObject.order + sendGAEcommerceEvent(gaEcommerceEventObject.action, event) + } + } + const userMsg = getStoredUserMessage(currentUser) if (userMsg) { addUserNotification({ diff --git a/frontend/public/src/lib/notificationsApi.js b/frontend/public/src/lib/notificationsApi.js index 6e65024f74..aa825ff16e 100644 --- a/frontend/public/src/lib/notificationsApi.js +++ b/frontend/public/src/lib/notificationsApi.js @@ -42,10 +42,13 @@ export function getStoredUserMessage(): UserMessage | null { export function determineUserActionForGoogleAnalytics() { const userMsg = ingestUserMessage() if (!userMsg) return null - const msgType = userMsgJson.type || null + const msgType = userMsg.type || null if (!msgType) return null if (msgType === USER_MSG_TYPE_PAYMENT_ACCEPTED) { - return "purchase" + return { + action: GOOGLE_ANALYTICS_EVENT_TYPE["GA_PURCHASE"], + order: userMsg.order + } } }