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

fix: provide worspaceId to AnalyticsInitializer #7642

Merged
merged 12 commits into from
Nov 15, 2021

Conversation

isalikov
Copy link
Contributor

@isalikov isalikov commented Nov 4, 2021

  • provide workspaceId for track events if cloud version

Closes #7596

@isalikov isalikov requested a review from jamakase November 4, 2021 17:09
@github-actions github-actions bot added area/frontend area/platform issues related to the platform labels Nov 4, 2021
@isalikov isalikov temporarily deployed to more-secrets November 4, 2021 17:09 Inactive
@isalikov isalikov temporarily deployed to more-secrets November 4, 2021 17:52 Inactive
@isalikov isalikov temporarily deployed to more-secrets November 5, 2021 09:50 Inactive
@isalikov isalikov temporarily deployed to more-secrets November 8, 2021 14:56 Inactive
@isalikov isalikov temporarily deployed to more-secrets November 8, 2021 15:01 Inactive
@isalikov isalikov temporarily deployed to more-secrets November 8, 2021 17:55 Inactive
@@ -31,7 +31,10 @@ import {
function useCustomerIdProvider() {
const workspace = useCurrentWorkspace();

return workspace.customerId;
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we have changed a bit logic to more declarative way, there is no need to change customerIdProvider anymore.

@@ -1,7 +1,10 @@
import { SegmentAnalytics } from "./types";

export class AnalyticsService {
constructor(private userId?: string, private version?: string) {}
constructor(
private context: Record<string, unknown>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like additionalContext suits better.

);

const handleAddContextProps = (props: Record<string, unknown>) => {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where it updates ctx

}: {
children: React.ReactNode;
version?: string;
userId?: string;
context?: Record<string, unknown>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to set all context at once. This prop makes it a bit confusing that you are providing context, however it provides additional context ( or initAnalyticsContext )


return {
[key]: ctx[key],
...result,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you are building from new object, there is no need to spread here and just result[key] could be used.

};

const handleRemoveContextProps = (props: string[]) => {
const newCtx = Object.keys(ctx).reduce((result, key) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like

Object.entries()
...
if(!props.includes(key)){
   result[key]=value;
}

return result;

is easier for understanding

const { workspaceId, customerId } = useCurrentWorkspace();
const { user } = useAuthService();

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's better to add it as a separate hook, so it could be used as.

useProvideAnalyticsProp({workspaceId, customerId} // or some other better name

so it will add and remove from context where necessary.

const { user } = useAuthService();

useEffect(() => {
ctx.setContext({ workspaceId, userId: user?.userId, customerId });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have useCurrentUser that is always present.

@jamakase jamakase temporarily deployed to more-secrets November 13, 2021 10:24 Inactive
@jamakase jamakase self-assigned this Nov 13, 2021
@jamakase jamakase temporarily deployed to more-secrets November 13, 2021 11:54 Inactive
@jamakase jamakase temporarily deployed to more-secrets November 15, 2021 12:46 Inactive
@jamakase jamakase merged commit 35e6795 into master Nov 15, 2021
@jamakase jamakase deleted the 7596/Rework-Webapp-segment-tracking branch November 15, 2021 15:32
schlattk pushed a commit to schlattk/airbyte that referenced this pull request Jan 4, 2022
* fix: provide worspaceId to AnalyticsInitializer

* Refactor Analytics for more independent approach

* Speed up initial load for cloud webapp

Co-authored-by: Artem Astapenko <jamakase54@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/platform issues related to the platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework Webapp segment tracking.
2 participants