forked from openedx-unsupported/frontend-app-payment
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Red Ventures event tracking to payment page (#25)
EDX-932 RV
- Loading branch information
1 parent
8e605c4
commit 4493f8d
Showing
30 changed files
with
927 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const cohesionConfig = { | ||
name: 'edx', | ||
slug: 'edx', | ||
domain: 'edx.org', | ||
domainLabel: 'edx', | ||
domainExtension: '.org', | ||
domainLabelWithExtension: 'edx.org', | ||
postTypeGql: '', | ||
homepageGql: '', | ||
siteUrl: process.env.MARKETING_SITE_BASE_URL, | ||
cmsUrl: process.env.NEXT_PUBLIC_WORDPRESS_URL || '', | ||
cmsUser: process.env.WP_USER || '', | ||
cmsPwd: process.env.WP_PWD || '', | ||
logoUrl: '', | ||
studyMatchUrl: '', | ||
voyagerUrl: '/discover', | ||
identityToken: '', | ||
gaCid: '', | ||
gaSid: '', | ||
gaMid: '', | ||
defaultDegree: '', | ||
defaultCategory: '', | ||
defaultSubject: '', | ||
tagularApiKey: '', | ||
tagularSourceKey: 'src_2euJfAVNt6Z9kQz4e9t1SQBtm8x', | ||
tagularWriteKey: 'wk_2euJfDkJVTtEVzsC8BPOb0g9dVj', | ||
tagularCookieDomain: 'edx.org', | ||
tagularDomainWhitelist: JSON.stringify([ | ||
'edx.org', | ||
]), | ||
monarchSourceId: '', | ||
monarchToken: '', | ||
newRelicAppID: '', | ||
newRelicVoyagerAppID: '', | ||
cookieLawId: '', | ||
}; | ||
|
||
module.exports = cohesionConfig; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const ElementType = { | ||
Link: 'LINK', | ||
Entry: 'ENTRY', | ||
Button: 'BUTTON', | ||
}; | ||
|
||
export const PaymentTitle = 'Payment | edX'; | ||
|
||
export const EventMap = { | ||
ProductClicked: 'redventures.ecommerce.v1.ProductClicked', | ||
ProductLoaded: 'redventures.ecommerce.v1.ProductLoaded', | ||
ProductViewed: 'redventures.ecommerce.v1.ProductViewed', | ||
ElementClicked: 'redventures.usertracking.v3.ElementClicked', | ||
ElementViewed: 'redventures.usertracking.v3.ElementViewed', | ||
FieldSelected: 'redventures.usertracking.v3.FieldSelected', | ||
FormSubmitted: 'redventures.usertracking.v3.FormSubmitted', | ||
FormViewed: 'redventures.usertracking.v3.FormViewed', | ||
ConversionTracked: 'core.conversions.ConversionTracked.v2', | ||
}; | ||
|
||
export const IS_FULLY_SHOWN_THRESHOLD_OR_MARGIN = 1.0; | ||
export const IS_SINGLE_PX_SHOWN_THRESHOLD_OR_MARGIN = 0.0; | ||
export const DOCUMENT_ROOT_NODE = null; | ||
|
||
export const defaultOptions = { | ||
threshold: IS_FULLY_SHOWN_THRESHOLD_OR_MARGIN, | ||
root: DOCUMENT_ROOT_NODE, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const DEFAULT_LOOKUP_VALUE = '*'; | ||
|
||
// enums cause noo-shadow errors in prospectus | ||
export const BaseTagularVariant = { | ||
Courses: 'courses', | ||
}; | ||
|
||
const TagularVariant = { | ||
// Include base/x-ref things | ||
...BaseTagularVariant, | ||
// Supplied from Data Team | ||
XSeries: 'certificates-xseries', | ||
ProfessionalCertificate: 'certificates-prof-cert', | ||
ExecEd: 'certificates-exec-ed', | ||
MicroBachelors: 'certificates-micro-bachelors', | ||
MicroMasters: 'certificates-micro-masters', | ||
Bachelors: 'degrees-bachelors', | ||
Masters: 'degrees-masters', | ||
Doctorate: 'degrees-doctorate', | ||
Bootcamps: 'bootcamps', | ||
// Not Final | ||
Certificates: 'degrees-certificates', | ||
Licenses: 'degrees-licenses', | ||
// Special Values | ||
All: 'all-products/mixed', | ||
Unknown: BaseTagularVariant.Courses, | ||
}; | ||
|
||
const typeToVariant = { | ||
[DEFAULT_LOOKUP_VALUE]: TagularVariant.Unknown, // missing value | ||
// type_attr Slugs | ||
bachelors: TagularVariant.Bachelors, | ||
masters: TagularVariant.Masters, | ||
microbachelors: TagularVariant.MicroBachelors, | ||
micromasters: TagularVariant.MicroMasters, | ||
'professional-certificate': TagularVariant.ProfessionalCertificate, | ||
// 'professional-program-wl': TagularVariant.Unknown, Whitelabel Programs are no more. | ||
xseries: TagularVariant.XSeries, | ||
doctorate: TagularVariant.Doctorate, | ||
license: TagularVariant.Licenses, | ||
certificate: TagularVariant.Certificates, | ||
// type_attr Display Names | ||
Bachelors: TagularVariant.Bachelors, | ||
Masters: TagularVariant.Masters, | ||
MicroBachelors: TagularVariant.MicroBachelors, | ||
MicroMasters: TagularVariant.MicroMasters, | ||
'Professional Certificate': TagularVariant.ProfessionalCertificate, | ||
// 'Professional Program': TagularVariant.Unknown, Whitelabel Programs are no more. | ||
XSeries: TagularVariant.XSeries, | ||
Doctorate: TagularVariant.Doctorate, | ||
License: TagularVariant.Licenses, | ||
Certificate: TagularVariant.Certificates, | ||
// course_type Slugs | ||
'executive-education-2u': TagularVariant.ExecEd, | ||
'bootcamp-2u': TagularVariant.Bootcamps, | ||
// Skipped as it was a note in the doc: 'Anything else': TagularVariant.Courses, | ||
// course_type Display Name | ||
'Executive Education': TagularVariant.ExecEd, | ||
'Boot Camp': TagularVariant.Bootcamps, | ||
Course: TagularVariant.Courses, | ||
}; | ||
|
||
export default function translateVariant(x) { | ||
return typeToVariant[x] || typeToVariant[DEFAULT_LOOKUP_VALUE]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Cookies from 'universal-cookie'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { EventMap } from './constants'; | ||
|
||
/** | ||
* Fetch or Create a Tagular CorrelationID. This also refreshes the cookie's expiry. | ||
*/ | ||
export const getCorrelationID = () => { | ||
const COOKIE_NAME = 'tglr_correlation_id'; | ||
const PARAM_NAME = 'correlationId'; | ||
|
||
function getQueryParameter(name) { | ||
const params = new URLSearchParams(window.location.search); | ||
|
||
return params.get(name); | ||
} | ||
|
||
let paramId = getQueryParameter(PARAM_NAME) || new Cookies().get(COOKIE_NAME); | ||
|
||
if (!paramId) { | ||
paramId = uuidv4(); | ||
} | ||
|
||
const expirationDate = new Date(); | ||
expirationDate.setMinutes(expirationDate.getMinutes() + 30); // 30 mins expiration from now | ||
new Cookies().set(COOKIE_NAME, paramId, { expires: expirationDate }); | ||
|
||
return paramId; | ||
}; | ||
|
||
/** | ||
* Submit ('beam') an event via Tagular to Make. | ||
* @param eventName Schema Name of the Event | ||
* @param eventData The data required by the schema | ||
*/ | ||
export const tagularEvent = (eventName, eventData) => { | ||
// if tagular is available, try sending given event with event data | ||
if (typeof window !== 'undefined' && window.tagular) { | ||
try { | ||
window.tagular('beam', eventName, { | ||
'@type': EventMap[eventName], | ||
...eventData, | ||
}); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Tagular event ${eventName} not sent.`, error); | ||
} | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.warn('Tagular not available on page.'); | ||
} | ||
}; | ||
|
||
/** | ||
* Make Near Slugs from Plain Strings for ease of eventing. | ||
* @example | ||
* "Computer Science" => "computer-science" | ||
* "Humanities & Arts" => "humanities-&-arts" | ||
* "Someone added a space " => "someone-added-a-space" | ||
* | ||
* @param x Input String | ||
*/ | ||
export function hyphenateForTagular(x) { | ||
return x | ||
.trim() | ||
.toLowerCase() | ||
.replace(/[^\w&]/g, '-'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.