From ce32d44c2711c8644899cb7f261596c82b987499 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 25 Jul 2024 13:44:35 -0600 Subject: [PATCH] refactor(tracker): changing `id` -> `uid` adding support for supplying `childUid` additionally made changes to the cookie order - specifically the priority was changed to favor child data over parent, and sku over uid --- docs/INTEGRATION_TRACKING.md | 42 +++-- packages/snap-preact-demo/public/cart.html | 4 +- packages/snap-preact-demo/public/order.html | 4 +- packages/snap-preact-demo/public/product.html | 2 +- .../tests/cypress/e2e/tracking/track.cy.js | 22 ++- packages/snap-tracker/README.md | 44 +++-- packages/snap-tracker/src/Tracker.test.ts | 160 ++++++++++++++---- packages/snap-tracker/src/Tracker.ts | 37 ++-- packages/snap-tracker/src/types.ts | 3 +- 9 files changed, 219 insertions(+), 99 deletions(-) diff --git a/docs/INTEGRATION_TRACKING.md b/docs/INTEGRATION_TRACKING.md index 17ccd5415..47e0a7057 100644 --- a/docs/INTEGRATION_TRACKING.md +++ b/docs/INTEGRATION_TRACKING.md @@ -19,14 +19,15 @@ searchspring.tracker.track.shopper.login({ ``` ### Product View -Tracks product page views. Should only be installed on product detail pages. An `id` and/or `sku` and/or `childSku` are required. +Tracks product page views. Should only be installed on product detail pages. A `uid` and/or `sku` and/or `childSku` and/or `childUid` are required (provide as many of these product identifiers that are available). ```html ``` @@ -35,9 +36,10 @@ Alternatively, this can also be integrated using the `searchspring.tracker.track ```typescript searchspring.tracker.track.product.view({ - id: '123', + uid: '123', sku: 'product123', - childSku: 'product123_a', + childUid: '123_a', + childSku: 'product123_a' }); ``` @@ -45,21 +47,23 @@ searchspring.tracker.track.product.view({ ### Cart View Tracks cart contents. Should only be installed on a cart page. If the checkout process does not contain a dedicated cart page (ie. slideout cart) then this method should be invoked when the cart comes into view. -Each item object must contain a `qty`, `price`, (`id` and/or `sku` and/or `childSku`) +Each item object must contain a `qty`, `price`, (`uid` and/or `sku` and/or `childSku` and/or `childUid` - provide as many of these product identifiers that are available). ```html diff --git a/packages/snap-preact-demo/tests/cypress/e2e/tracking/track.cy.js b/packages/snap-preact-demo/tests/cypress/e2e/tracking/track.cy.js index 4ffd5d931..a4cc82b16 100644 --- a/packages/snap-preact-demo/tests/cypress/e2e/tracking/track.cy.js +++ b/packages/snap-preact-demo/tests/cypress/e2e/tracking/track.cy.js @@ -2,11 +2,15 @@ import { BeaconType, BeaconCategory } from '@searchspring/snap-tracker'; describe('Tracking', () => { beforeEach(() => { + cy.clearCookies(); + cy.on('window:before:load', (win) => { win.mergeSnapConfig = { mode: 'production', }; }); + + cy.wait(1000); }); it('tracked shopper login', () => { cy.visit('https://localhost:2222'); @@ -89,7 +93,7 @@ describe('Tracking', () => { expect(beacon.category).to.equal(BeaconCategory.PAGEVIEW); expect(beacon.event).to.be.an('object').to.include.all.keys(['sku']); - expect(beacon.event.id).to.equal('182146'); + expect(beacon.event.uid).to.equal('182146'); expect(beacon.event.sku).to.equal('C-AD-W1-1869P'); }); @@ -123,16 +127,16 @@ describe('Tracking', () => { expect(beacon.event).to.have.property('items'); expect(beacon.event.items).to.be.an('array').to.have.length(2); - expect(beacon.event.items[0]).to.be.an('object').include.all.keys(['id', 'sku', 'qty', 'price']); - expect(beacon.event.items[1]).to.be.an('object').include.all.keys(['id', 'sku', 'qty', 'price']); + expect(beacon.event.items[0]).to.be.an('object').include.all.keys(['uid', 'sku', 'qty', 'price']); + expect(beacon.event.items[1]).to.be.an('object').include.all.keys(['uid', 'sku', 'qty', 'price']); expect(beacon.event.items[0]).to.deep.equal({ - id: '182146', + uid: '182146', sku: 'C-AD-W1-1869P', qty: '1', price: '48', }); expect(beacon.event.items[1]).to.deep.equal({ - id: '174287', + uid: '174287', sku: 'C-AD-Y5-814MD', qty: '1', price: '36', @@ -172,17 +176,17 @@ describe('Tracking', () => { expect(beacon.event).to.have.property('items'); expect(beacon.event.items).to.be.an('array').to.have.length(2); - expect(beacon.event.items[0]).to.be.an('object').include.all.keys(['id', 'sku', 'qty', 'price']); - expect(beacon.event.items[1]).to.be.an('object').include.all.keys(['id', 'sku', 'qty', 'price']); + expect(beacon.event.items[0]).to.be.an('object').include.all.keys(['uid', 'sku', 'qty', 'price']); + expect(beacon.event.items[1]).to.be.an('object').include.all.keys(['uid', 'sku', 'qty', 'price']); expect(beacon.event.items[0]).to.deep.equal({ - id: '99688', + uid: '99688', sku: 'C-BP-G7-B1469', qty: '1', price: '22', }); expect(beacon.event.items[1]).to.deep.equal({ - id: '181655', + uid: '181655', sku: 'C-VJ-P2-32007', qty: '1', price: '39', diff --git a/packages/snap-tracker/README.md b/packages/snap-tracker/README.md index 7a5f3cf11..f35aecc98 100644 --- a/packages/snap-tracker/README.md +++ b/packages/snap-tracker/README.md @@ -83,8 +83,9 @@ This method will call the `retarget` method on all `DomTargeters` set in the Tra ```html @@ -96,15 +97,17 @@ This method will call the `retarget` method on all `DomTargeters` set in the Tra