From 365f784926ac45a925db3cdc9b2638c85962e01f Mon Sep 17 00:00:00 2001 From: Yair Dovrat Date: Mon, 17 Jun 2024 15:23:20 +0200 Subject: [PATCH] ZRZ-1318 fix engagement time --- src/index.ts | 7 +------ src/requestBuilder.ts | 15 ++++----------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/index.ts b/src/index.ts index e708f37..9253118 100644 --- a/src/index.ts +++ b/src/index.ts @@ -77,11 +77,7 @@ export const sendEvent = async ( ) => { const { client } = event const { finalURL, requestBody } = getFinalURL(eventType, event, settings) - console.log( - '🚀🚀🚀🚀🚀🚀🚀🚀 final URL is here and send event fires', - finalURL - ) - console.log('🚀🚀🚀🚀🚀🚀🚀🚀 also manager.fetch is working: ', manager.fetch) + manager.fetch(finalURL, { headers: { 'User-Agent': client.userAgent }, }) @@ -109,7 +105,6 @@ export default async function (manager: Manager, settings: ComponentSettings) { ) manager.addEventListener('pageview', event => { - // this line does not trigger visibilityChange after a pagview, it will start triggering events only on the fist change to hidden event.client.attachEvent('visibilityChange') // if engagement duration is >1 send a user_engagement event before pageview, to count the time on previous page properly diff --git a/src/requestBuilder.ts b/src/requestBuilder.ts index 5ad7984..2b58726 100644 --- a/src/requestBuilder.ts +++ b/src/requestBuilder.ts @@ -12,10 +12,8 @@ const getRandomInt = () => Math.floor(2147483647 * Math.random()) const firstPageEvent = (client: Client) => { const countedEvent = client.get('countedEvent') if (countedEvent) { - console.log('🥑🥑🥑🥑🥑🥑🥑 this is not the first event!') return false } else { - console.log('🥑🥑🥑🥑🥑🥑🥑 this is the FIRST event!') return true } } @@ -125,22 +123,17 @@ function getToolRequest( firstPageEvent(client) ) { requestBody._et = engagementDuration - console.log( - '💡💡💡💡💡💡💡💡 event/ecommerce includes _et: ', - requestBody._et - ) + // mark first event to avoid sending _et with upcoming events on that page event.client.set('countedEvent', '1', { scope: 'page' }) - // Reset engagementDuration after event has been dispatched so it does not accumulate + // Reset engagementDuration and engagementStart after event has been dispatched so it does not accumulate event.client.set('engagementDuration', '0') + const now = new Date(Date.now()).getTime() + event.client.set('engagementStart', `${now}`) } else if (eventType === 'user_engagement') { requestBody._et = engagementDuration // Reset engagementDuration after event has been dispatched so it does not accumulate event.client.set('engagementDuration', '0') - console.log( - '🐝🐝🐝🐝🐝🐝🐝 user_engagement includes _et: ', - requestBody._et - ) } /* Start of gclid treating */