2022-01-31 21:14:51 +00:00
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
2021-12-22 06:13:39 +00:00
|
|
|
import { logError } from '~/lib/logger';
|
|
|
|
|
2022-01-27 03:14:06 +00:00
|
|
|
const SKU_PREMIUM = '2c92a00d76f0d5060176f2fb0a5029ff';
|
|
|
|
const SKU_ULTIMATE = '2c92a0ff76f0d5250176f2f8c86f305a';
|
|
|
|
const PRODUCT_INFO = {
|
|
|
|
[SKU_PREMIUM]: {
|
|
|
|
// eslint-disable-next-line @gitlab/require-i18n-strings
|
|
|
|
name: 'Premium',
|
|
|
|
id: '0002',
|
2022-02-03 09:14:03 +00:00
|
|
|
price: '228',
|
2022-01-27 03:14:06 +00:00
|
|
|
variant: 'SaaS',
|
|
|
|
},
|
|
|
|
[SKU_ULTIMATE]: {
|
|
|
|
// eslint-disable-next-line @gitlab/require-i18n-strings
|
|
|
|
name: 'Ultimate',
|
|
|
|
id: '0001',
|
2022-02-03 09:14:03 +00:00
|
|
|
price: '1188',
|
2022-01-27 03:14:06 +00:00
|
|
|
variant: 'SaaS',
|
|
|
|
},
|
|
|
|
};
|
2022-06-14 12:08:53 +00:00
|
|
|
const EMPTY_NAMESPACE_ID_VALUE = 'not available';
|
2022-01-27 03:14:06 +00:00
|
|
|
|
2022-01-31 21:14:51 +00:00
|
|
|
const generateProductInfo = (sku, quantity) => {
|
|
|
|
const product = PRODUCT_INFO[sku];
|
|
|
|
|
|
|
|
if (!product) {
|
|
|
|
logError('Unexpected product sku provided to generateProductInfo');
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const productInfo = {
|
|
|
|
...product,
|
|
|
|
brand: 'GitLab',
|
|
|
|
category: 'DevOps',
|
|
|
|
quantity,
|
|
|
|
};
|
|
|
|
|
|
|
|
return productInfo;
|
|
|
|
};
|
|
|
|
|
2021-12-22 06:13:39 +00:00
|
|
|
const isSupported = () => Boolean(window.dataLayer) && gon.features?.gitlabGtmDatalayer;
|
|
|
|
|
|
|
|
const pushEvent = (event, args = {}) => {
|
|
|
|
if (!window.dataLayer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
window.dataLayer.push({
|
|
|
|
event,
|
|
|
|
...args,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
logError('Unexpected error while pushing to dataLayer', e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-04 12:17:40 +00:00
|
|
|
const pushEnhancedEcommerceEvent = (event, args = {}) => {
|
2022-01-27 03:14:06 +00:00
|
|
|
if (!window.dataLayer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-02-04 12:17:40 +00:00
|
|
|
window.dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object
|
2022-01-27 03:14:06 +00:00
|
|
|
window.dataLayer.push({
|
|
|
|
event,
|
|
|
|
...args,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
logError('Unexpected error while pushing to dataLayer', e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-12-22 06:13:39 +00:00
|
|
|
const pushAccountSubmit = (accountType, accountMethod) =>
|
|
|
|
pushEvent('accountSubmit', { accountType, accountMethod });
|
|
|
|
|
|
|
|
const trackFormSubmission = (accountType) => {
|
|
|
|
const form = document.getElementById('new_new_user');
|
|
|
|
form.addEventListener('submit', () => {
|
|
|
|
pushAccountSubmit(accountType, 'form');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const trackOmniAuthSubmission = (accountType) => {
|
|
|
|
const links = document.querySelectorAll('.js-oauth-login');
|
|
|
|
links.forEach((link) => {
|
|
|
|
const { provider } = link.dataset;
|
|
|
|
link.addEventListener('click', () => {
|
|
|
|
pushAccountSubmit(accountType, provider);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const trackFreeTrialAccountSubmissions = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trackFormSubmission('freeThirtyDayTrial');
|
|
|
|
trackOmniAuthSubmission('freeThirtyDayTrial');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const trackNewRegistrations = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trackFormSubmission('standardSignUp');
|
|
|
|
trackOmniAuthSubmission('standardSignUp');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const trackSaasTrialSubmit = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-13 18:16:51 +00:00
|
|
|
pushEvent('saasTrialSubmit');
|
2021-12-22 06:13:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const trackSaasTrialSkip = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const skipLink = document.querySelector('.js-skip-trial');
|
|
|
|
skipLink.addEventListener('click', () => {
|
|
|
|
pushEvent('saasTrialSkip');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const trackSaasTrialGroup = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-12 21:13:49 +00:00
|
|
|
const form = document.querySelector('.js-saas-trial-group');
|
2021-12-22 06:13:39 +00:00
|
|
|
form.addEventListener('submit', () => {
|
|
|
|
pushEvent('saasTrialGroup');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-02-25 18:18:45 +00:00
|
|
|
export const trackProjectImport = () => {
|
2021-12-22 06:13:39 +00:00
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const importButtons = document.querySelectorAll('.js-import-project-btn');
|
|
|
|
importButtons.forEach((button) => {
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
const { platform } = button.dataset;
|
2022-02-25 18:18:45 +00:00
|
|
|
pushEvent('projectImport', { platform });
|
2021-12-22 06:13:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const trackSaasTrialGetStarted = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const getStartedButton = document.querySelector('.js-get-started-btn');
|
|
|
|
getStartedButton.addEventListener('click', () => {
|
|
|
|
pushEvent('saasTrialGetStarted');
|
|
|
|
});
|
|
|
|
};
|
2022-01-27 03:14:06 +00:00
|
|
|
|
2022-07-11 09:08:40 +00:00
|
|
|
export const trackTrialAcceptTerms = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pushEvent('saasTrialAcceptTerms');
|
|
|
|
};
|
|
|
|
|
2022-01-27 03:14:06 +00:00
|
|
|
export const trackCheckout = (selectedPlan, quantity) => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-31 21:14:51 +00:00
|
|
|
const product = generateProductInfo(selectedPlan, quantity);
|
2022-01-27 03:14:06 +00:00
|
|
|
|
2022-01-31 21:14:51 +00:00
|
|
|
if (Object.keys(product).length === 0) {
|
2022-01-27 03:14:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const eventData = {
|
|
|
|
ecommerce: {
|
2022-02-04 12:17:40 +00:00
|
|
|
currencyCode: 'USD',
|
2022-01-27 03:14:06 +00:00
|
|
|
checkout: {
|
|
|
|
actionField: { step: 1 },
|
2022-01-31 21:14:51 +00:00
|
|
|
products: [product],
|
2022-01-27 03:14:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// eslint-disable-next-line @gitlab/require-i18n-strings
|
2022-02-04 12:17:40 +00:00
|
|
|
pushEnhancedEcommerceEvent('EECCheckout', eventData);
|
2022-01-27 03:14:06 +00:00
|
|
|
};
|
2022-01-31 21:14:51 +00:00
|
|
|
|
2022-06-14 12:08:53 +00:00
|
|
|
export const getNamespaceId = () => {
|
|
|
|
return window.gl.snowplowStandardContext?.data?.namespace_id || EMPTY_NAMESPACE_ID_VALUE;
|
|
|
|
};
|
|
|
|
|
2022-01-31 21:14:51 +00:00
|
|
|
export const trackTransaction = (transactionDetails) => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const transactionId = uuidv4();
|
|
|
|
const { paymentOption, revenue, tax, selectedPlan, quantity } = transactionDetails;
|
|
|
|
const product = generateProductInfo(selectedPlan, quantity);
|
2022-06-14 12:08:53 +00:00
|
|
|
const namespaceId = getNamespaceId();
|
2022-01-31 21:14:51 +00:00
|
|
|
|
|
|
|
if (Object.keys(product).length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const eventData = {
|
|
|
|
ecommerce: {
|
2022-02-04 12:17:40 +00:00
|
|
|
currencyCode: 'USD',
|
2022-01-31 21:14:51 +00:00
|
|
|
purchase: {
|
|
|
|
actionField: {
|
|
|
|
id: transactionId,
|
|
|
|
affiliation: 'GitLab',
|
|
|
|
option: paymentOption,
|
2022-02-03 09:14:03 +00:00
|
|
|
revenue: revenue.toString(),
|
|
|
|
tax: tax.toString(),
|
2022-01-31 21:14:51 +00:00
|
|
|
},
|
2022-06-14 12:08:53 +00:00
|
|
|
products: [{ ...product, dimension36: namespaceId }],
|
2022-01-31 21:14:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-02-04 12:17:40 +00:00
|
|
|
pushEnhancedEcommerceEvent('EECtransactionSuccess', eventData);
|
2022-01-31 21:14:51 +00:00
|
|
|
};
|
2022-02-22 18:17:57 +00:00
|
|
|
|
2022-04-20 00:09:27 +00:00
|
|
|
export const pushEECproductAddToCartEvent = () => {
|
2022-02-22 18:17:57 +00:00
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-20 00:09:27 +00:00
|
|
|
window.dataLayer.push({
|
|
|
|
event: 'EECproductAddToCart',
|
|
|
|
ecommerce: {
|
|
|
|
currencyCode: 'USD',
|
|
|
|
add: {
|
|
|
|
products: [
|
|
|
|
{
|
|
|
|
name: 'CI/CD Minutes',
|
|
|
|
id: '0003',
|
|
|
|
price: '10',
|
|
|
|
brand: 'GitLab',
|
|
|
|
category: 'DevOps',
|
|
|
|
variant: 'add-on',
|
|
|
|
quantity: 1,
|
|
|
|
},
|
|
|
|
],
|
2022-02-22 18:17:57 +00:00
|
|
|
},
|
2022-04-20 00:09:27 +00:00
|
|
|
},
|
2022-02-22 18:17:57 +00:00
|
|
|
});
|
|
|
|
};
|
2022-02-24 03:15:17 +00:00
|
|
|
|
2022-04-20 00:09:27 +00:00
|
|
|
export const trackAddToCartUsageTab = () => {
|
|
|
|
const getStartedButton = document.querySelector('.js-buy-additional-minutes');
|
|
|
|
if (!getStartedButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getStartedButton.addEventListener('click', pushEECproductAddToCartEvent);
|
|
|
|
};
|
|
|
|
|
2022-02-24 03:15:17 +00:00
|
|
|
export const trackCombinedGroupProjectForm = () => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const form = document.querySelector('.js-groups-projects-form');
|
|
|
|
form.addEventListener('submit', () => {
|
|
|
|
pushEvent('combinedGroupProjectFormSubmit');
|
|
|
|
});
|
|
|
|
};
|
2022-08-25 03:10:55 +00:00
|
|
|
|
|
|
|
export const trackCompanyForm = (aboutYourCompanyType) => {
|
|
|
|
if (!isSupported()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pushEvent('aboutYourCompanyFormSubmit', { aboutYourCompanyType });
|
|
|
|
};
|