Skip to content

Commit

Permalink
move to outer app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniw committed Aug 12, 2024
1 parent 211ff4c commit aeb0e37
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions ecommerce/views/v0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 1 addition & 13 deletions frontend/public/src/components/NotificationContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -59,17 +56,8 @@ export class NotificationContainer extends React.Component<Props, State> {

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 (
<div className="notifications order-2" id="notifications-container">
{Object.keys(userNotifications).map((notificationKey, i) => {
Expand Down
13 changes: 13 additions & 0 deletions frontend/public/src/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -45,6 +49,15 @@ export class App extends React.Component<Props, void> {
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({
Expand Down
7 changes: 5 additions & 2 deletions frontend/public/src/lib/notificationsApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit aeb0e37

Please sign in to comment.