Skip to content

Commit

Permalink
FFWEB-3065: Implement cart and login tracking
Browse files Browse the repository at this point in the history
Implement cart and login tracking
  • Loading branch information
Rayn93 committed Jun 3, 2024
1 parent 47424db commit 12365be
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
62 changes: 30 additions & 32 deletions src/view/frontend/templates/ff/communication.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,35 @@ $searchImmediate = $communicationParameters['search-immediate'] ?? 'false';
</script>
<?php endif; ?>

<script>
document.addEventListener('ffCoreReady', ({ factfinder }) => {
const cookies = document.cookie.split('; ').reduce((acc, cookie) => {
const cookieData = cookie.split('=');
const [key, value] = cookieData;
acc[key] = value;

return acc;
}, {});

const clearCookie = (name) => {
document.cookie = name+'=; Max-Age=-1;';
}

if (cookies['ff_user_id']) {
factfinder.config.defaults.general.userId = cookies['ff_user_id'];

<!--<script>-->
<!-- document.addEventListener('ffCoreReady', ({ factfinder, searchImmediate }) => {-->
<!-- const cookies = document.cookie.split('; ').reduce((acc, cookie) => {-->
<!-- const cookieData = cookie.split('=');-->
<!-- const [key, value] = cookieData;-->
<!-- acc[key] = value;-->
<!---->
<!-- return acc;-->
<!-- }, {});-->
<!---->
<!-- const clearCookie = (name) => {-->
<!-- document.cookie = name+'=; Max-Age=-1;';-->
<!-- }-->
<!---->
<!-- if (cookies['ff_user_id']) {-->
<!-- factfinder.communication.sessionManager.setLoginData(cookies['ff_user_id'])-->
<!---->
<!-- if (cookies['ff_has_just_logged_in']) {-->
<!-- clearCookie('ff_has_just_logged_in');-->
<!-- factfinder.communication.Tracking.loginWithConfig();-->
<!-- }-->
<!-- } else {-->
<!-- factfinder.communication.sessionManager.clearLoginData();-->
<!---->
<!-- if (cookies['ff_has_just_logged_out']) {-->
<!-- clearCookie('ff_has_just_logged_out');-->
<!-- factfinder.communication.sessionManager.clearAllSessionData();-->
<!-- }-->
<!-- }-->
<!---->
<!--// });-->
<!--//</script>-->
if (cookies['ff_has_just_logged_in']) {
clearCookie('ff_has_just_logged_in');
factfinder.tracking.login([{
sid: JSON.parse(localStorage.ffwebco).sid,
userId: factfinder.config.defaults.general.userId
}]);
}
} else {
if (cookies['ff_has_just_logged_out']) {
clearCookie('ff_has_just_logged_out');
factfinder.config.defaults.general.userId = undefined
}
}
});
</script>
9 changes: 4 additions & 5 deletions src/view/frontend/web/js/catalog-add-to-cart-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ define([
});

if (qtyInput && cartItem) {
const track = new factfinder.communication.Tracking12();
track.cart({
channel: factfinder.communication.globalSearchParameter.channel,
const track = factfinder.tracking;
track.cart([{
id: cartItem.product_sku,
price: cartItem.product_price_value,
masterId: eventData.sku || cartItem.product_sku,
count: parseInt(qtyInput.value),
userId: factfinder.communication.globalCommunicationParameter.userId
});
sid: JSON.parse(localStorage.ffwebco).sid
}]);
}

subscription.dispose();
Expand Down

0 comments on commit 12365be

Please sign in to comment.