Skip to content

Commit

Permalink
feat: Cohesion identify event firing, modify ConversionTracked (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk authored Nov 14, 2024
1 parent 963501c commit 70da326
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
41 changes: 41 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,47 @@
multiparty: true,
}
})

try {
if (window.cohesion) {
window.cohesion("tagular:ready", function () {
window.analytics.ready(function () {
const cohesionAnonymId = window.tagular("getAliasSet")["anonymousId"];
const segmentAnonymId = window.analytics.user().anonymousId();
const segmentUserId = window.analytics.user().id();

// Segment Identify
window.analytics.identify(segmentUserId, {
cohesion_anonymous_id: cohesionAnonymId,
});

// Tagular Identify
window.tagular("beam", {
"@type": "core.Identify.v1",
traits: {},
externalIds: [
{
id: segmentAnonymId,
type: "segment_anonymous_id",
collection: "users",
encoding: "none",
},
{
id: cohesionAnonymId,
type: "cohesion_anonymous_id",
collection: "users",
encoding: "none",
},
],
});
});
})
} else {
console.log('Cohesion is not defined');
}
} catch(e) {
console.log('Cohesion error: ', e);
}
</script>
<% } %>
</head>
Expand Down
8 changes: 7 additions & 1 deletion src/cohesion/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export const getCorrelationID = () => {
const COOKIE_NAME = 'tglr_correlation_id';
const PARAM_NAME = 'correlationId';

function getDomain() {
const { hostname } = window.location;
const parts = hostname.split('.');
return parts.length > 2 ? parts.slice(-2).join('.') : hostname;
}

function getQueryParameter(name) {
const params = new URLSearchParams(window.location.search);

Expand All @@ -23,7 +29,7 @@ export const getCorrelationID = () => {

const expirationDate = new Date();
expirationDate.setMinutes(expirationDate.getMinutes() + 30); // 30 mins expiration from now
new Cookies().set(COOKIE_NAME, paramId, { expires: expirationDate });
new Cookies().set(COOKIE_NAME, paramId, { expires: expirationDate, domain: `.${getDomain()}` });

return paramId;
};
Expand Down
3 changes: 2 additions & 1 deletion src/payment/checkout/Checkout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ class Checkout extends React.Component {
if (products || products.length !== 0) {
products.forEach(product => {
productList.push({
externalId: String(product.courseKey || ''),
variant: BaseTagularVariant.Courses, // TODO: all are 'courses' now, use translateVariant() in the future
brand: this.getPartnerName(product), // School or Partner name
name: product.title, // Course(s) title
name: String(product.title || ''), // Course(s) title
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/payment/payment-methods/paypal/PayPalButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const PayPalButton = ({ intl, isProcessing, ...props }) => {
const elementId = entry.target?.id;
const tagularElement = {
elementType: ElementType.Button,
position: elementId,
position: String(elementId || ''),
name: 'paypal',
text: 'PayPal',
};
Expand Down

0 comments on commit 70da326

Please sign in to comment.