-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
ui: Release notes signup - Add Custom Analytics actions and sagas #44821
Merged
craig
merged 1 commit into
cockroachdb:master
from
koorosh:ui-release-notes-signup__custom_analytics_service
Feb 25, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
pkg/ui/src/redux/customAnalytics/customAnalyticsSagas.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { expectSaga } from "redux-saga-test-plan"; | ||
import sinon from "sinon"; | ||
import Analytics from "analytics-node"; | ||
|
||
import { signUpEmailSubscription } from "./customAnalyticsSagas"; | ||
import { | ||
completeEmailSubscriptionSignUp, | ||
signUpForEmailSubscription, | ||
} from "./customAnanlyticsActions"; | ||
|
||
const sandbox = sinon.createSandbox(); | ||
|
||
describe("customAnalyticsSagas", () => { | ||
describe("signUpEmailSubscription generator", () => { | ||
afterEach(() => { | ||
sandbox.reset(); | ||
}); | ||
|
||
it("calls analytics#identify with user email in args ", () => { | ||
const analyticsIdentifyFn = sandbox.stub(Analytics.prototype, "identify"); | ||
const clusterId = "cluster-1"; | ||
const email = "foo@bar.com"; | ||
const action = signUpForEmailSubscription(clusterId, email); | ||
|
||
return expectSaga(signUpEmailSubscription, action) | ||
.put(completeEmailSubscriptionSignUp()) | ||
.dispatch(action) | ||
.run() | ||
.then(() => { | ||
const expectedAnalyticsMessage = { | ||
userId: clusterId, | ||
traits: { | ||
email, | ||
}, | ||
}; | ||
analyticsIdentifyFn.calledOnceWith(expectedAnalyticsMessage); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { call, put, takeEvery } from "redux-saga/effects"; | ||
import Analytics from "analytics-node"; | ||
|
||
import { PayloadAction } from "src/interfaces/action"; | ||
import { COCKROACHLABS_ADDR } from "src/util/cockroachlabsAPI"; | ||
import { | ||
completeEmailSubscriptionSignUp, | ||
EMAIL_SUBSCRIPTION_SIGN_UP, | ||
EmailSubscriptionSignUpPayload, | ||
} from "./customAnanlyticsActions"; | ||
|
||
export type AnalyticsClientTarget = "email_sign_up"; | ||
|
||
// TODO (koorosh): has to be moved out from code base | ||
const EMAIL_SIGN_UP_CLIENT_KEY = "72EEC0nqQKfoLWq0ZcGoTkJFIG9G9SII"; | ||
|
||
const analyticsOpts = { | ||
host: COCKROACHLABS_ADDR + "/api/segment", | ||
}; | ||
|
||
export function getAnalyticsClientFor(target: AnalyticsClientTarget): Analytics { | ||
switch (target) { | ||
case "email_sign_up": | ||
return new Analytics(EMAIL_SIGN_UP_CLIENT_KEY, analyticsOpts); | ||
default: | ||
throw new Error("Unrecognized Analytics Client target."); | ||
} | ||
} | ||
|
||
export function* signUpEmailSubscription(action: PayloadAction<EmailSubscriptionSignUpPayload>) { | ||
const client = getAnalyticsClientFor("email_sign_up"); | ||
const { clusterId, email } = action.payload; | ||
yield call([client, client.identify], { | ||
userId: clusterId, | ||
traits: { | ||
email, | ||
}, | ||
}); | ||
yield put(completeEmailSubscriptionSignUp()); | ||
} | ||
|
||
export function* customAnalyticsSaga() { | ||
yield takeEvery(EMAIL_SUBSCRIPTION_SIGN_UP, signUpEmailSubscription); | ||
} |
37 changes: 37 additions & 0 deletions
37
pkg/ui/src/redux/customAnalytics/customAnanlyticsActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { Action } from "redux"; | ||
|
||
import { PayloadAction } from "src/interfaces/action"; | ||
|
||
export const EMAIL_SUBSCRIPTION_SIGN_UP = "cockroachui/customanalytics/EMAIL_SUBSCRIPTION_SIGN_UP"; | ||
export const EMAIL_SUBSCRIPTION_SIGN_UP_COMPLETE = "cockroachui/customanalytics/EMAIL_SUBSCRIPTION_SIGN_UP_COMPLETE"; | ||
|
||
export type EmailSubscriptionSignUpPayload = { | ||
email: string; | ||
clusterId: string; | ||
}; | ||
|
||
export function signUpForEmailSubscription(clusterId: string, email: string): PayloadAction<EmailSubscriptionSignUpPayload> { | ||
return { | ||
type: EMAIL_SUBSCRIPTION_SIGN_UP, | ||
payload: { | ||
email, | ||
clusterId, | ||
}, | ||
}; | ||
} | ||
|
||
export function completeEmailSubscriptionSignUp(): Action { | ||
return { | ||
type: EMAIL_SUBSCRIPTION_SIGN_UP_COMPLETE, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
export * from "./customAnalyticsSagas"; | ||
export * from "./customAnanlyticsActions"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, we'll just leave this in-line since we do the same in
analytics.ts
, but good to leave the TODO.