Skip to content
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

Change the track product view mutation call to other place #326

Merged
merged 3 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions blocks/product-details/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ProductQuantity from '@dropins/storefront-pdp/containers/ProductQuantity.
import ProductDescription from '@dropins/storefront-pdp/containers/ProductDescription.js';
import ProductAttributes from '@dropins/storefront-pdp/containers/ProductAttributes.js';
import ProductGallery from '@dropins/storefront-pdp/containers/ProductGallery.js';
import trackViewedProduct from '../../scripts/api/productTracking.js';

// Libs
import { setJsonLd } from '../../scripts/commerce.js';
Expand Down Expand Up @@ -221,10 +220,6 @@ export default async function decorate(block) {
pdpRendered.render(ProductAttributes, {})($attributes),
]);

if (product) {
trackViewedProduct(product.sku);
}

// Lifecycle Events
events.on('pdp/valid', (valid) => {
// update add to cart button disabled state based on product selection validity
Expand Down
1 change: 1 addition & 0 deletions scripts/api/productTracking.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-cycle */
import { getSignInToken, performMonolithGraphQLQuery } from '../commerce.js';

const trackViewedProductMutation = `
Expand Down
5 changes: 5 additions & 0 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { getConfigValue } from './configs.js';
import { getUserTokenCookie } from './initializers/index.js';
import { getConsent } from './scripts.js';
import trackViewedProduct from './api/productTracking.js';

async function initAnalytics() {
// Load Commerce events SDK and collector
Expand Down Expand Up @@ -34,6 +35,10 @@ async function initAnalytics() {
},
);

window.adobeDataLayer.push((dl) => {
dl.addEventListener('product-page-view', ({ eventInfo }) => trackViewedProduct(eventInfo.productContext.sku));
});

// Load events SDK and collector
import('./commerce-events-sdk.js');
import('./commerce-events-collector.js');
Expand Down