From 8af06b5f8ef48d3c9f6747e93f31e1dc4f93831d Mon Sep 17 00:00:00 2001 From: harlyon Date: Wed, 28 Dec 2022 15:07:11 +0200 Subject: [PATCH 1/2] added the is staff flag --- .eslintrc | 6 ++---- package.json | 2 +- react/modules/extraEvents.ts | 9 ++++++++- react/package.json | 4 +++- react/tsconfig.json | 30 +++++++++++++++++++++++------- react/typings/events.d.ts | 1 + react/yarn.lock | 8 ++++++++ 7 files changed, 46 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index bc9d79b9..9713dfdd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,8 +2,6 @@ "extends": "vtex", "root": true, "env": { - "node": true, - "es6": true, - "jest": true + "node": true } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 35bd6707..222ed030 100644 --- a/package.json +++ b/package.json @@ -30,4 +30,4 @@ "prettier": "^1.19.1", "typescript": "^3.7.5" } -} +} \ No newline at end of file diff --git a/react/modules/extraEvents.ts b/react/modules/extraEvents.ts index f21e3964..e90ff356 100644 --- a/react/modules/extraEvents.ts +++ b/react/modules/extraEvents.ts @@ -1,6 +1,8 @@ import push from './push' import { PixelMessage } from '../typings/events' +window.dataLayer = window.dataLayer || [] + async function emailToHash(email:string) { const msgUint8 = new TextEncoder().encode(email); @@ -12,6 +14,9 @@ async function emailToHash(email:string) { export async function sendExtraEvents(e: PixelMessage) { + const staffObject = window.dataLayer.find(item => item.hasOwnProperty('is_staff')); + const is_Staff = staffObject.is_staff; + switch (e.data.eventName) { case 'vtex:pageView': { push({ @@ -29,6 +34,7 @@ export async function sendExtraEvents(e: PixelMessage) { case 'vtex:userData': { const { data } = e + console.log(data, 'data') if (!data.isAuthenticated) { return @@ -39,7 +45,8 @@ export async function sendExtraEvents(e: PixelMessage) { push({ event: 'userData', userId: data.id, - emailHash: emailHash + emailHash: emailHash, + isStaff: is_Staff, }) break diff --git a/react/package.json b/react/package.json index 7fa4298f..cf3f07b7 100644 --- a/react/package.json +++ b/react/package.json @@ -7,6 +7,8 @@ "license": "ISC", "devDependencies": { "@types/node": "^12.0.0", - "@vtex/test-tools": "^3.3.2" + "@vtex/test-tools": "^3.3.2", + "vtex.pixel-interfaces": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-interfaces@1.1.1/public/_types/react", + "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.6/public/@types/vtex.render-runtime" } } diff --git a/react/tsconfig.json b/react/tsconfig.json index 5d95a952..b0b2f0c0 100644 --- a/react/tsconfig.json +++ b/react/tsconfig.json @@ -4,8 +4,12 @@ "esModuleInterop": true, "allowJs": true, "jsx": "react", - "lib": ["es2017", "dom", "es2018.promise"], - "module": "es6", + "lib": [ + "es2017", + "dom", + "es2018.promise" + ], + "module": "esnext", "moduleResolution": "node", "noEmitOnError": true, "noImplicitAny": true, @@ -19,12 +23,24 @@ "strictNullChecks": true, "strictPropertyInitialization": true, "target": "es2017", - "typeRoots": ["node_modules/@types"], - "types": ["node", "jest", "graphql"] + "typeRoots": [ + "node_modules/@types" + ], + "types": [ + "node", + "jest", + "graphql" + ] }, - "exclude": ["node_modules"], - "include": ["./typings/*.d.ts", "./**/*.tsx", "./**/*.ts"], + "exclude": [ + "node_modules" + ], + "include": [ + "./typings/*.d.ts", + "./**/*.tsx", + "./**/*.ts" + ], "typeAcquisition": { "enable": false } -} +} \ No newline at end of file diff --git a/react/typings/events.d.ts b/react/typings/events.d.ts index ec26396e..93f23961 100644 --- a/react/typings/events.d.ts +++ b/react/typings/events.d.ts @@ -43,6 +43,7 @@ export interface UserData extends PageInfoData { email?: string phone?: string isAuthenticated: boolean + isStaff: boolean } export interface CartIdData extends PageInfoData { diff --git a/react/yarn.lock b/react/yarn.lock index c05e598f..aa956bfd 100644 --- a/react/yarn.lock +++ b/react/yarn.lock @@ -5096,6 +5096,14 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" +"vtex.pixel-interfaces@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-interfaces@1.1.1/public/_types/react": + version "0.0.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-interfaces@1.1.1/public/_types/react#fa7a0347e046eab3dd768998fc9252b2c0dd5aef" + +"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.6/public/@types/vtex.render-runtime": + version "8.132.6" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.6/public/@types/vtex.render-runtime#166e916d8aadbee0cfc4d48a02d3c3e8f2834fc9" + w3c-hr-time@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045" From 66d73168aadb995e9dd3e142f62062e133fda283 Mon Sep 17 00:00:00 2001 From: harlyon Date: Wed, 28 Dec 2022 15:15:20 +0200 Subject: [PATCH 2/2] ChangeLog changes --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1827f356..65a33e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - +### Added +- Added a isStaff field to "userData" dataLayer ## [Unreleased] ## [3.3.1] - 2022-04-04