forked from openedx-unsupported/frontend-app-payment
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Red Ventures event tracking to payment page #25
Merged
Merged
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1a22a2b
feat: Add cohesion config to htmlWebpackPlugin options
julianajlk 69c4447
feat: Add cohesion snippet to index.html
julianajlk 920a38f
feat: Add trackPaymentButtonClick on PayPal button
julianajlk 3e1c233
feat: Add cohesion directory with helper functions
julianajlk 187958f
feat: Add tracking data for elementClicked and elementViewed to Check…
julianajlk 0d629dd
feat: Add tracking to AlertMessage for coupon code banner
julianajlk 9baf8fd
refactor: Modify contants and actions/reducers to fit changes done in…
julianajlk d7d74ac
refactor: Add RV tracking to handleSubmitPayment saga on success/fail…
julianajlk 406b2d1
fix: Add hyphenateForTagular helper
julianajlk 4638b7e
feat: Add dataTranslationMatrices file
julianajlk 952a594
fix: Delete hooks.js file not needed
julianajlk 630c382
refactor: Remove uniqueness from events in AlertMessage
julianajlk 7317203
refactor: Remove uniqueness from events in Checkout
julianajlk 43af071
feat: Att getCorrelationID helper
julianajlk 4ef7f83
feat: Add correlationID to action creators for elementViewed and clicked
julianajlk c605238
chore: Install uuid dependency
julianajlk a537505
fix: Remove IntersectionObserver and add PayPalButton back in parent …
julianajlk cf6e794
feat: Add IntersectionObserver to PayPalButton and PlaceOrderButton
julianajlk b76579f
test: Update existing tests
julianajlk de33c82
test: Update snapshots
julianajlk d3ce906
chore: Update allowlist advisories
julianajlk c2be3c1
fix: Add siteUrl cohesionConfig from settings
julianajlk 25a7891
fix: Feedback edits
julianajlk 7356019
fix: Click events are not the same, updating event structure
julianajlk c1cd3aa
fix: Add cohesionConfig to htmlWebpackPlugin userOptions as well
julianajlk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'; | ||
|
||
julianajlk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add ConversionTracked here.... See: https://github.com/edx/prospectus/blob/master/src/utils/cohesion/constants/tagular/events.ts#L10
The full events structure should be: https://github.com/edx/prospectus/pull/7366/files#diff-fb92d5744536e627aa25a0491348c6b15ecc9b675824e12097fa34379c9785f7R217
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example structure of a ConversionTracked event (this is just a console.log, not actually a Tagular Debug log):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name is blank for the product, should also be run through hyphenateForTagular but looks great otherwise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
in this case is the course title so it should not be hyphenated. It's null in local but should be populated in stage/prodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... ok, ive been told otherwise, but cool