Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Integrate Heap analytics into the website #866

Merged
merged 8 commits into from
Jul 13, 2018

Conversation

fragosti
Copy link
Contributor

@fragosti fragosti commented Jul 11, 2018

Description

I basically removed react-ga, included Heap (which is not available as a UMD module) and replaced all the calls to GA with calls to Heap.

I increased the amount of data we are logging and improved the way we are logging the data since Heap provides a better / more expansive API.
https://docs.heapanalytics.com/reference#addeventproperties.

I also fixed onPageLoadAsync which wasn't actually working.

Testing instructions

Play around with the website and go to our heap dashboard (I can send invite) and see how things are going! The main reason we want this is for the SQL feature though.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Change requires a change to the documentation.
  • Added tests to cover my changes.
  • Added new entries to the relevant CHANGELOG.jsons.
  • Labeled this PR with the 'WIP' label if it is a work in progress.
  • Labeled this PR with the labels corresponding to the changed package.

@coveralls
Copy link

coveralls commented Jul 11, 2018

Coverage Status

Coverage decreased (-0.2%) to 84.341% when pulling ee54438 on feature/website/integrate-heap into b82fdd5 on v2-prototype.

this._heap = heap;
}
// HeapAnalytics Wrappers
public async indentifyAsync(id: string, idType: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to my comment in the sourcemaps PR, is there a clean way to isolate the no floating promises rule to this file and change the api to be non async? It will be less confusing that way, so it is explicit that the code does not need to be awaited

@@ -313,14 +313,13 @@ export const utils = {
const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
return baseUrl;
},
async onPageLoadAsync(): Promise<void> {
onPageLoadPromise: new Promise((resolve, _reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm this is a bit inconsistent with how we normally handle promises, is this functionally different than creating a new promise each time? Was the main issue that resolve wasn't being called in the if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that you can't set window.onload = resolve multiple times (ie. for multiple promises, a new one created for each function call) because window.onload can only be one function and is only called once. So with the previous method here is what would happen:

window.onload = A
window.onload = B
window.onload = C
window.onload() // C is called

The Promises made for A and B are never resolves and await forever. Imho this is the best way to do it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, are we at risk of never resolving if we set window.onload too late?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, the only onPageLoadAsync() that worked was the last call, all previous Promises that were returned will never resolve because window.onload points to the latest resolve function. Calling onPageLoadAsync() after window.onload worked fine because we checked for that and returned.

@@ -112,6 +113,9 @@ export class SubscribeForm extends React.Component<SubscribeFormProps, Subscribe
try {
const response = await backendClient.subscribeToNewsletterAsync(this.state.emailText);
const status = response.status === 200 ? SubscribeFormStatus.Success : SubscribeFormStatus.Error;
if (status === SubscribeFormStatus.Success) {
analytics.indentify(this.state.emailText, 'email');
Copy link
Contributor

Choose a reason for hiding this comment

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

typo? "identify"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wow. Great catch

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants