Commit 7d5f74ee authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'gitlab-com/buyer-experience#233' into 'master'

Add to cart event for Google Tag Manager

See merge request gitlab-org/gitlab!80691
parents a8b0c4f0 360dab06
...@@ -231,3 +231,32 @@ export const trackTransaction = (transactionDetails) => { ...@@ -231,3 +231,32 @@ export const trackTransaction = (transactionDetails) => {
pushEnhancedEcommerceEvent('EECtransactionSuccess', eventData); pushEnhancedEcommerceEvent('EECtransactionSuccess', eventData);
}; };
export const trackAddToCartUsageTab = () => {
if (!isSupported()) {
return;
}
const getStartedButton = document.querySelector('.js-buy-additional-minutes');
getStartedButton.addEventListener('click', () => {
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,
},
],
},
},
});
});
};
...@@ -3,6 +3,7 @@ import SeatUsageApp from 'ee/usage_quotas/seats'; ...@@ -3,6 +3,7 @@ import SeatUsageApp from 'ee/usage_quotas/seats';
import initNamespaceStorage from 'ee/usage_quotas/storage/init_namespace_storage'; import initNamespaceStorage from 'ee/usage_quotas/storage/init_namespace_storage';
import initCiMinutesUsageApp from 'ee/usage_quotas/ci_minutes_usage'; import initCiMinutesUsageApp from 'ee/usage_quotas/ci_minutes_usage';
import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs'; import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs';
import { trackAddToCartUsageTab } from '~/google_tag_manager';
const initLinkedTabs = () => { const initLinkedTabs = () => {
if (!document.querySelector('.js-storage-tabs')) { if (!document.querySelector('.js-storage-tabs')) {
...@@ -55,3 +56,4 @@ const fixPipelinesPagination = () => { ...@@ -55,3 +56,4 @@ const fixPipelinesPagination = () => {
fixPipelinesPagination(); fixPipelinesPagination();
initVueApps(); initVueApps();
initLinkedTabs(); initLinkedTabs();
trackAddToCartUsageTab();
import ciMinutesUsage from 'ee/ci_minutes_usage'; import ciMinutesUsage from 'ee/ci_minutes_usage';
import initNamespaceStorage from 'ee/usage_quotas/storage/init_namespace_storage'; import initNamespaceStorage from 'ee/usage_quotas/storage/init_namespace_storage';
import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs'; import LinkedTabs from '~/lib/utils/bootstrap_linked_tabs';
import { trackAddToCartUsageTab } from '~/google_tag_manager';
if (document.querySelector('#js-storage-counter-app')) { if (document.querySelector('#js-storage-counter-app')) {
initNamespaceStorage(); initNamespaceStorage();
...@@ -14,3 +15,4 @@ if (document.querySelector('#js-storage-counter-app')) { ...@@ -14,3 +15,4 @@ if (document.querySelector('#js-storage-counter-app')) {
} }
ciMinutesUsage(); ciMinutesUsage();
trackAddToCartUsageTab();
import mountSubscriptionsApplication from 'ee/subscriptions/buy_minutes'; import mountSubscriptionsApplication from 'ee/subscriptions/buy_minutes';
import { trackAddToCartUsageTab } from '~/google_tag_manager';
mountSubscriptionsApplication(document.getElementById('js-buy-minutes')); mountSubscriptionsApplication(document.getElementById('js-buy-minutes'));
trackAddToCartUsageTab();
...@@ -5,6 +5,10 @@ class Profiles::UsageQuotasController < Profiles::ApplicationController ...@@ -5,6 +5,10 @@ class Profiles::UsageQuotasController < Profiles::ApplicationController
feature_category :purchase feature_category :purchase
before_action only: [:index] do
push_frontend_feature_flag(:gitlab_gtm_datalayer, type: :ops)
end
def index def index
@hide_search_settings = true @hide_search_settings = true
@namespace = current_user.namespace @namespace = current_user.namespace
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
.pipeline-quota.container-fluid .pipeline-quota.container-fluid
.row .row
.col-sm-6.offset-sm-6 .col-sm-6.offset-sm-6
- if ::Gitlab.com? - if ::Gitlab.dev_env_or_com?
= link_to s_('UsageQuota|Buy additional minutes'), = link_to s_('UsageQuota|Buy additional minutes'),
buy_additional_minutes_path(namespace), buy_additional_minutes_path(namespace),
target: buy_addon_target_attr(namespace), target: buy_addon_target_attr(namespace),
class: 'gl-button btn btn-confirm float-right', class: 'gl-button btn btn-confirm float-right js-buy-additional-minutes',
data: { track_action: 'click_buy_ci_minutes', track_label: namespace.actual_plan_name, track_property: 'pipeline_quota_page' } data: { track_action: 'click_buy_ci_minutes', track_label: namespace.actual_plan_name, track_property: 'pipeline_quota_page' }
.row .row
......
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
trackSaasTrialGetStarted, trackSaasTrialGetStarted,
trackCheckout, trackCheckout,
trackTransaction, trackTransaction,
trackAddToCartUsageTab,
} from '~/google_tag_manager'; } from '~/google_tag_manager';
import { setHTMLFixture } from 'helpers/fixtures'; import { setHTMLFixture } from 'helpers/fixtures';
import { logError } from '~/lib/logger'; import { logError } from '~/lib/logger';
...@@ -173,6 +174,32 @@ describe('~/google_tag_manager/index', () => { ...@@ -173,6 +174,32 @@ describe('~/google_tag_manager/index', () => {
}, },
], ],
}), }),
createTestCase(trackAddToCartUsageTab, {
links: [
{
cls: 'js-buy-additional-minutes',
expectation: {
event: 'EECproductAddToCart',
ecommerce: {
currencyCode: 'USD',
add: {
products: [
{
name: 'CI/CD Minutes',
id: '0003',
price: '10',
brand: 'GitLab',
category: 'DevOps',
variant: 'add-on',
quantity: 1,
},
],
},
},
},
},
],
}),
])('%p', (subject, { links = [], forms = [], expectedEvents }) => { ])('%p', (subject, { links = [], forms = [], expectedEvents }) => {
beforeEach(() => { beforeEach(() => {
setHTMLFixture(createHTML({ links, forms })); setHTMLFixture(createHTML({ links, forms }));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment