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

Added the is staff flag to GTM #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"extends": "vtex",
"root": true,
"env": {
"node": true,
"es6": true,
"jest": true
"node": true
}
}
}
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"prettier": "^1.19.1",
"typescript": "^3.7.5"
}
}
}
9 changes: 8 additions & 1 deletion react/modules/extraEvents.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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({
Expand All @@ -29,6 +34,7 @@ export async function sendExtraEvents(e: PixelMessage) {

case 'vtex:userData': {
const { data } = e
console.log(data, 'data')

if (!data.isAuthenticated) {
return
Expand All @@ -39,7 +45,8 @@ export async function sendExtraEvents(e: PixelMessage) {
push({
event: 'userData',
userId: data.id,
emailHash: emailHash
emailHash: emailHash,
isStaff: is_Staff,
})

break
Expand Down
4 changes: 3 additions & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
30 changes: 23 additions & 7 deletions react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
}
}
1 change: 1 addition & 0 deletions react/typings/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface UserData extends PageInfoData {
email?: string
phone?: string
isAuthenticated: boolean
isStaff: boolean
}

export interface CartIdData extends PageInfoData {
Expand Down
8 changes: 8 additions & 0 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down