From ea2780a9ce6f91919e5a24221dc4552c43afd1e6 Mon Sep 17 00:00:00 2001 From: jakobhero Date: Wed, 21 Jul 2021 10:30:55 +0000 Subject: [PATCH] [analytics] fixed anonymous ID in identify() --- components/server/package.json | 2 + .../src/auth/login-completion-handler.ts | 7 ++- components/server/src/server.ts | 3 ++ components/server/src/user/user-controller.ts | 1 - yarn.lock | 45 +++++++++---------- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/components/server/package.json b/components/server/package.json index 1c6a129b343aa0..619bc6968d79c4 100644 --- a/components/server/package.json +++ b/components/server/package.json @@ -47,6 +47,7 @@ "bitbucket": "^2.4.2", "body-parser": "^1.18.2", "cookie": "^0.4.1", + "cookie-parser": "^1.4.5", "cors": "^2.8.4", "deep-equal": "^1.0.1", "deepmerge": "^2.2.1", @@ -82,6 +83,7 @@ "ws": "^7.4.6" }, "devDependencies": { + "@types/cookie-parser": "^1.4.2", "@graphql-codegen/cli": "^1.19.4", "@graphql-codegen/introspection": "^1.18.1", "@graphql-codegen/typescript": "^1.19.0", diff --git a/components/server/src/auth/login-completion-handler.ts b/components/server/src/auth/login-completion-handler.ts index 34865ca4881bc2..18b2b4e3050372 100644 --- a/components/server/src/auth/login-completion-handler.ts +++ b/components/server/src/auth/login-completion-handler.ts @@ -79,8 +79,13 @@ export class LoginCompletionHandler { this.gitpodCookie.setCookie(response); if (authHost) { + increaseLoginCounter("succeeded", authHost); - this.analytics.identify({ anonymousId: request.sessionID, userId: user.id }); + + //read anonymous ID set by analytics.js + let anonymousId = request.cookies.ajs_anonymous_id; + //make identify call if anonymous ID was found + if (anonymousId) this.analytics.identify({anonymousId: anonymousId.replace(/(^"|"$)/g, ''),userId:user.id}); this.analytics.track({ userId: user.id, event: "login", diff --git a/components/server/src/server.ts b/components/server/src/server.ts index a09a7f86770e5a..28278396dc4535 100644 --- a/components/server/src/server.ts +++ b/components/server/src/server.ts @@ -8,6 +8,7 @@ import * as http from 'http'; import * as express from 'express'; import * as ws from 'ws'; import * as bodyParser from 'body-parser'; +import * as cookieParser from 'cookie-parser'; import { injectable, inject } from 'inversify'; import * as prom from 'prom-client'; import { SessionHandlerProvider } from './session-handler'; @@ -97,6 +98,8 @@ export class Server { // Read bodies as JSON app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: true })) + // Add cookie Parser + app.use(cookieParser()); app.set('trust proxy', 1) // trust first proxy // Install Sessionhandler diff --git a/components/server/src/user/user-controller.ts b/components/server/src/user/user-controller.ts index 247cd51f8ca871..aed2a122c9bc85 100644 --- a/components/server/src/user/user-controller.ts +++ b/components/server/src/user/user-controller.ts @@ -510,7 +510,6 @@ export class UserController { await this.userService.updateUserEnvVarsOnLogin(user, envVars); await this.userService.acceptCurrentTerms(user); - this.analytics.identify({ anonymousId: req.sessionID || "unknown", userId: user.id, }); this.analytics.track({ userId: user.id, event: "signup", diff --git a/yarn.lock b/yarn.lock index 3a4fe85d937bac..baf6300e12c775 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4197,6 +4197,13 @@ dependencies: "@types/node" "*" +"@types/cookie-parser@^1.4.2": + version "1.4.2" + resolved "https://registry.yarnpkg.com/@types/cookie-parser/-/cookie-parser-1.4.2.tgz#e4d5c5ffda82b80672a88a4281aaceefb1bd9df5" + integrity sha512-uwcY8m6SDQqciHsqcKDGbo10GdasYsPCYkH3hVegj9qAah6pX5HivOnOuI3WYmyQMnOATV39zv/Ybs0bC/6iVg== + dependencies: + "@types/express" "*" + "@types/cookiejar@*": version "2.1.0" resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.0.tgz#4b7daf2c51696cfc70b942c11690528229d1a1ce" @@ -4725,7 +4732,7 @@ "@types/history" "*" "@types/react" "*" -"@types/react@*", "@types/react@17.0.0", "@types/react@^17.0.0": +"@types/react@*", "@types/react@^17.0.0": version "17.0.0" resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.0.tgz#5af3eb7fad2807092f0046a1302b7823e27919b8" integrity sha512-aj/L7RIMsRlWML3YB6KZiXB3fV2t41+5RBGYF8z+tAKU43Px8C3cYUZsDvf1/+Bm4FK21QWBrDutu8ZJ/70qOw== @@ -8030,6 +8037,14 @@ convert-source-map@^0.3.3: resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-0.3.5.tgz#f1d802950af7dd2631a1febe0596550c86ab3190" integrity sha1-8dgClQr33SYxof6+BZZVDIarMZA= +cookie-parser@^1.4.5: + version "1.4.5" + resolved "https://registry.yarnpkg.com/cookie-parser/-/cookie-parser-1.4.5.tgz#3e572d4b7c0c80f9c61daf604e4336831b5d1d49" + integrity sha512-f13bPUj/gG/5mDr+xLmSxxDsB9DQiTIfhJS/sqjrmfAWiAN+x2O4i/XguTL9yDZ+/IFDanJ+5x7hC4CXT9Tdzw== + dependencies: + cookie "0.4.0" + cookie-signature "1.0.6" + cookie-signature@1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c" @@ -14914,7 +14929,7 @@ mz@^2.4.0: object-assign "^4.0.1" thenify-all "^1.0.0" -nan@2.14.1, nan@^2.12.1, nan@^2.13.2, nan@^2.14.0, nan@^2.9.2: +nan@^2.12.1, nan@^2.13.2, nan@^2.9.2: version "2.14.1" resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.1.tgz#d7be34dfa3105b91494c3147089315eff8874b01" integrity sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw== @@ -15479,13 +15494,6 @@ onetime@^5.1.2: dependencies: mimic-fn "^2.1.0" -oniguruma@7.2.1: - version "7.2.1" - resolved "https://registry.yarnpkg.com/oniguruma/-/oniguruma-7.2.1.tgz#51775834f7819b6e31aa878706aa7f65ad16b07f" - integrity sha512-WPS/e1uzhswPtJSe+Zls/kAj27+lEqZjCmRSjnYk/Z4L2Mu+lJC2JWtkZhPJe4kZeTQfz7ClcLyXlI4J68MG2w== - dependencies: - nan "^2.14.0" - open@^7.0.2: version "7.4.2" resolved "https://registry.yarnpkg.com/open/-/open-7.4.2.tgz#b8147e26dcf3e426316c730089fd71edd29c2321" @@ -17643,7 +17651,7 @@ react-dev-utils@^11.0.3: strip-ansi "6.0.0" text-table "0.2.0" -react-dom@17.0.1, react-dom@^17.0.1: +react-dom@^17.0.1: version "17.0.1" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.1.tgz#1de2560474ec9f0e334285662ede52dbc5426fc6" integrity sha512-6eV150oJZ9U2t9svnsspTMrWNyHc6chX0KzDeAOXftRa8bNeOKTTfCJ7KorIwenkHd2xqVTBTCZd79yk/lx/Ug== @@ -17772,7 +17780,7 @@ react-scripts@^4.0.3: optionalDependencies: fsevents "^2.1.3" -react@17.0.1, react@^17.0.1: +react@^17.0.1: version "17.0.1" resolved "https://registry.yarnpkg.com/react/-/react-17.0.1.tgz#6e0600416bd57574e3f86d92edba3d9008726127" integrity sha512-lG9c9UuMHdcAexXtigOZLX8exLWkW0Ku29qPRU8uhF2R9BN96dLCt0psvzPLlHc5OWkgymP3qwTRgbnw5BKx3w== @@ -21033,24 +21041,11 @@ vm-browserify@^1.0.1: resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019" integrity sha512-iq+S7vZJE60yejDYM0ek6zg308+UZsdtPExWP9VZoCFCz1zkJoXFnAX7aZfd/ZwrkidzdUZL0C/ryW+JwAiIGw== -vscode-jsonrpc@^5.0.0, vscode-jsonrpc@^5.0.1: +vscode-jsonrpc@^5.0.0: version "5.0.1" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-5.0.1.tgz#9bab9c330d89f43fc8c1e8702b5c36e058a01794" integrity sha512-JvONPptw3GAQGXlVV2utDcHx0BiY34FupW/kI6mZ5x06ER5DdPG/tXWMVHjTNULF5uKPOUUD0SaXg5QaubJL0A== -vscode-languageserver-protocol@3.15.3: - version "3.15.3" - resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.15.3.tgz#3fa9a0702d742cf7883cb6182a6212fcd0a1d8bb" - integrity sha512-zrMuwHOAQRhjDSnflWdJG+O2ztMWss8GqUUB8dXLR/FPenwkiBNkMIJJYfSN6sgskvsF0rHAoBowNQfbyZnnvw== - dependencies: - vscode-jsonrpc "^5.0.1" - vscode-languageserver-types "3.15.1" - -vscode-languageserver-types@3.15.1: - version "3.15.1" - resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.15.1.tgz#17be71d78d2f6236d414f0001ce1ef4d23e6b6de" - integrity sha512-+a9MPUQrNGRrGU630OGbYVQ+11iOIovjCkqxajPa9w57Sd5ruK8WQNsslzpa0x/QJqC8kRc2DUxWjIFwoNm4ZQ== - vscode-uri@^1.0.1: version "1.0.8" resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.8.tgz#9769aaececae4026fb6e22359cb38946580ded59"