Skip to content

Commit 4f579c9

Browse files
Merge pull request #1591 from rocket-admin/feat/add-posthog-tracking
add PostHog analytics tracking alongside Amplitude
2 parents aadc39f + 13ff49f commit 4f579c9

File tree

99 files changed

+5551
-5032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5551
-5032
lines changed

frontend/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
class="nav-bar__upgrade-button"
154154
angulartics2On="click"
155155
angularticsAction="Demo navbar: Create account is clicked"
156-
(click)="logoutAndRedirectToRegistration()">
156+
(click)="logoutAndRedirectToRegistration(); posthog.capture('Demo navbar: Create account is clicked')">
157157
Create account
158158
</button>
159159

frontend/src/app/app.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { User } from '@sentry/angular';
1515
import amplitude from 'amplitude-js';
1616
import { Angulartics2, Angulartics2Amplitude, Angulartics2OnModule } from 'angulartics2';
1717
import { differenceInMilliseconds } from 'date-fns';
18+
import posthog from 'posthog-js';
1819
import { Subject } from 'rxjs';
1920
import { filter } from 'rxjs/operators';
2021
import { environment } from '../environments/environment';
@@ -23,6 +24,7 @@ import { Connection } from './models/connection';
2324
import { AuthService } from './services/auth.service';
2425
import { CompanyService } from './services/company.service';
2526
import { ConnectionsService } from './services/connections.service';
27+
import { PosthogService } from './services/posthog.service';
2628
import { TablesService } from './services/tables.service';
2729
import { UiSettingsService } from './services/ui-settings.service';
2830
import { UserService } from './services/user.service';
@@ -53,6 +55,7 @@ amplitude.getInstance().init('9afd282be91f94da735c11418d5ff4f5');
5355
],
5456
})
5557
export class AppComponent {
58+
protected posthog = posthog;
5659
public isSaas = (environment as any).saas;
5760
public appVersion = version;
5861
userActivity;
@@ -95,6 +98,7 @@ export class AppComponent {
9598
private angulartics2: Angulartics2,
9699
private domSanitizer: DomSanitizer,
97100
private matIconRegistry: MatIconRegistry,
101+
_posthog: PosthogService,
98102
) {
99103
this.matIconRegistry.addSvgIcon(
100104
'mysql',
@@ -167,6 +171,7 @@ export class AppComponent {
167171
this.angulartics2.eventTrack.next({
168172
action: 'Demo account is logged in',
169173
});
174+
posthog.capture('Demo account is logged in');
170175
});
171176
}
172177
});

frontend/src/app/components/api-keys/api-keys.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ <h1 class="mat-h1">API Keys</h1>
1818
data-testid="api-key-input"
1919
angulartics2On="change"
2020
angularticsAction="API Keys: api key title is edited"
21+
(change)="posthog.capture('API Keys: api key title is edited')"
2122
[(ngModel)]="generatingAPIkeyTitle">
2223
</mat-form-field>
2324
<button type="submit" mat-flat-button color="primary" data-testid="generate-api-key-button"
Lines changed: 85 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { CdkCopyToClipboard } from '@angular/cdk/clipboard';
22
import { CommonModule } from '@angular/common';
3+
import { Component, OnInit } from '@angular/core';
34
import { FormsModule } from '@angular/forms';
45
import { MatButtonModule } from '@angular/material/button';
56
import { MatDialog } from '@angular/material/dialog';
@@ -8,97 +9,102 @@ import { MatIconModule } from '@angular/material/icon';
89
import { MatInputModule } from '@angular/material/input';
910
import { MatListModule } from '@angular/material/list';
1011
import { MatTooltipModule } from '@angular/material/tooltip';
11-
import { CdkCopyToClipboard } from '@angular/cdk/clipboard';
12-
import { Angulartics2, Angulartics2OnModule } from 'angulartics2';
1312
import { Title } from '@angular/platform-browser';
14-
15-
import { AlertComponent } from '../ui-components/alert/alert.component';
16-
import { ProfileSidebarComponent } from '../profile/profile-sidebar/profile-sidebar.component';
17-
import { UserService } from 'src/app/services/user.service';
13+
import { Angulartics2, Angulartics2OnModule } from 'angulartics2';
14+
import posthog from 'posthog-js';
15+
import { ApiKey } from 'src/app/models/user';
1816
import { CompanyService } from 'src/app/services/company.service';
1917
import { NotificationsService } from 'src/app/services/notifications.service';
20-
import { ApiKey } from 'src/app/models/user';
21-
import { ApiKeyDeleteDialogComponent } from '../user-settings/api-key-delete-dialog/api-key-delete-dialog.component';
18+
import { UserService } from 'src/app/services/user.service';
19+
import { ProfileSidebarComponent } from '../profile/profile-sidebar/profile-sidebar.component';
2220
import { PlaceholderApiKeysListComponent } from '../skeletons/placeholder-api-keys-list/placeholder-api-keys-list.component';
21+
import { AlertComponent } from '../ui-components/alert/alert.component';
22+
import { ApiKeyDeleteDialogComponent } from '../user-settings/api-key-delete-dialog/api-key-delete-dialog.component';
2323

2424
@Component({
25-
selector: 'app-api-keys',
26-
templateUrl: './api-keys.component.html',
27-
styleUrls: ['./api-keys.component.css'],
28-
imports: [
29-
CommonModule,
30-
FormsModule,
31-
MatButtonModule,
32-
MatFormFieldModule,
33-
MatIconModule,
34-
MatInputModule,
35-
MatListModule,
36-
MatTooltipModule,
37-
CdkCopyToClipboard,
38-
Angulartics2OnModule,
39-
AlertComponent,
40-
ProfileSidebarComponent,
41-
PlaceholderApiKeysListComponent,
42-
]
25+
selector: 'app-api-keys',
26+
templateUrl: './api-keys.component.html',
27+
styleUrls: ['./api-keys.component.css'],
28+
imports: [
29+
CommonModule,
30+
FormsModule,
31+
MatButtonModule,
32+
MatFormFieldModule,
33+
MatIconModule,
34+
MatInputModule,
35+
MatListModule,
36+
MatTooltipModule,
37+
CdkCopyToClipboard,
38+
Angulartics2OnModule,
39+
AlertComponent,
40+
ProfileSidebarComponent,
41+
PlaceholderApiKeysListComponent,
42+
],
4343
})
4444
export class ApiKeysComponent implements OnInit {
45-
public apiKeys: ApiKey[] = null;
46-
public generatingAPIkeyTitle: string = '';
47-
public generatedAPIkeyHash: string = '';
48-
public submitting: boolean = false;
45+
protected posthog = posthog;
46+
public apiKeys: ApiKey[] = null;
47+
public generatingAPIkeyTitle: string = '';
48+
public generatedAPIkeyHash: string = '';
49+
public submitting: boolean = false;
4950

50-
constructor(
51-
private _userService: UserService,
52-
private _company: CompanyService,
53-
private _notifications: NotificationsService,
54-
private dialog: MatDialog,
55-
private title: Title,
56-
private angulartics2: Angulartics2,
57-
) {}
51+
constructor(
52+
private _userService: UserService,
53+
private _company: CompanyService,
54+
private _notifications: NotificationsService,
55+
private dialog: MatDialog,
56+
private title: Title,
57+
private angulartics2: Angulartics2,
58+
) {}
5859

59-
ngOnInit(): void {
60-
this._company.getCurrentTabTitle().subscribe(tabTitle => {
61-
this.title.setTitle(`API Keys | ${tabTitle || 'Rocketadmin'}`);
62-
});
63-
this.getAPIkeys();
64-
}
60+
ngOnInit(): void {
61+
this._company.getCurrentTabTitle().subscribe((tabTitle) => {
62+
this.title.setTitle(`API Keys | ${tabTitle || 'Rocketadmin'}`);
63+
});
64+
this.getAPIkeys();
65+
}
6566

66-
getAPIkeys() {
67-
this._userService.getAPIkeys().subscribe(res => this.apiKeys = res);
68-
}
67+
getAPIkeys() {
68+
this._userService.getAPIkeys().subscribe((res) => (this.apiKeys = res));
69+
}
6970

70-
generateAPIkey() {
71-
this.submitting = true;
72-
this._userService.generateAPIkey(this.generatingAPIkeyTitle).subscribe(res => {
73-
this.generatedAPIkeyHash = res.hash;
74-
this.generatingAPIkeyTitle = '';
75-
this.getAPIkeys();
76-
this.submitting = false;
77-
this.angulartics2.eventTrack.next({
78-
action: 'API Keys: key generated successfully',
79-
});
80-
}, () => {
81-
this.submitting = false;
82-
});
83-
}
71+
generateAPIkey() {
72+
this.submitting = true;
73+
this._userService.generateAPIkey(this.generatingAPIkeyTitle).subscribe(
74+
(res) => {
75+
this.generatedAPIkeyHash = res.hash;
76+
this.generatingAPIkeyTitle = '';
77+
this.getAPIkeys();
78+
this.submitting = false;
79+
this.angulartics2.eventTrack.next({
80+
action: 'API Keys: key generated successfully',
81+
});
82+
posthog.capture('API Keys: key generated successfully');
83+
},
84+
() => {
85+
this.submitting = false;
86+
},
87+
);
88+
}
8489

85-
deleteAPIkey(apiKey: ApiKey) {
86-
const deleteConfirmation = this.dialog.open(ApiKeyDeleteDialogComponent, {
87-
width: '25em',
88-
data: apiKey
89-
});
90+
deleteAPIkey(apiKey: ApiKey) {
91+
const deleteConfirmation = this.dialog.open(ApiKeyDeleteDialogComponent, {
92+
width: '25em',
93+
data: apiKey,
94+
});
9095

91-
deleteConfirmation.afterClosed().subscribe(action => {
92-
if (action === 'delete') {
93-
this.getAPIkeys();
94-
this.angulartics2.eventTrack.next({
95-
action: 'API Keys: key deleted successfully',
96-
});
97-
}
98-
});
99-
}
96+
deleteConfirmation.afterClosed().subscribe((action) => {
97+
if (action === 'delete') {
98+
this.getAPIkeys();
99+
this.angulartics2.eventTrack.next({
100+
action: 'API Keys: key deleted successfully',
101+
});
102+
posthog.capture('API Keys: key deleted successfully');
103+
}
104+
});
105+
}
100106

101-
showCopyNotification(message: string) {
102-
this._notifications.showSuccessSnackbar(message);
103-
}
107+
showCopyNotification(message: string) {
108+
this._notifications.showSuccessSnackbar(message);
109+
}
104110
}

frontend/src/app/components/audit/audit.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ <h1>Audit</h1>
77
<mat-select
88
angulartics2On="click"
99
angularticsAction="Audit: table is selected"
10+
(click)="posthog.capture('Audit: table is selected')"
1011
[(ngModel)]="tableName"
1112
(ngModelChange)="loadLogsPage()">
1213
<mat-option value="showAll">Show all</mat-option>
@@ -23,6 +24,7 @@ <h1>Audit</h1>
2324
<mat-select
2425
angulartics2On="click"
2526
angularticsAction="Audit: user is selected"
27+
(click)="posthog.capture('Audit: user is selected')"
2628
[(ngModel)]="userEmail" (ngModelChange)="loadLogsPage()">
2729
<mat-option value="showAll">Show all</mat-option>
2830
<mat-option *ngFor="let user of usersList" [value]="user.email">{{user.email}}</mat-option>
@@ -103,7 +105,7 @@ <h3 class='mat-subheading-2'>Rocketadmin can not find any tables</h3>
103105
<button mat-button color="accent"
104106
angulartics2On="click"
105107
angularticsAction="Audit: view changes is clicked"
106-
(click)="openInfoLogDialog(element)">
108+
(click)="openInfoLogDialog(element); posthog.capture('Audit: view changes is clicked')">
107109
Details
108110
</button>
109111
</td>

frontend/src/app/components/audit/audit.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { AsyncPipe, NgClass, NgForOf, NgIf } from '@angular/common';
22
import { Component, OnInit, ViewChild } from '@angular/core';
33
import { FormsModule } from '@angular/forms';
44
import { MatButtonModule } from '@angular/material/button';
5-
import { MatIconModule } from '@angular/material/icon';
65
import { MatDialog } from '@angular/material/dialog';
76
import { MatFormFieldModule } from '@angular/material/form-field';
7+
import { MatIconModule } from '@angular/material/icon';
88
import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator';
99
import { MatSelectModule } from '@angular/material/select';
1010
import { MatTableModule } from '@angular/material/table';
1111
import { Title } from '@angular/platform-browser';
1212
import { RouterModule } from '@angular/router';
1313
import { User } from '@sentry/angular';
1414
import { Angulartics2OnModule } from 'angulartics2';
15+
import posthog from 'posthog-js';
1516
import { merge } from 'rxjs';
1617
import { take, tap } from 'rxjs/operators';
1718
import { normalizeTableName } from 'src/app/lib/normalize';
@@ -52,6 +53,7 @@ import { InfoDialogComponent } from './info-dialog/info-dialog.component';
5253
styleUrls: ['./audit.component.css'],
5354
})
5455
export class AuditComponent implements OnInit {
56+
protected posthog = posthog;
5557
public isSaas = (environment as any).saas;
5658
public connectionID: string;
5759
public accesLevel: string;

frontend/src/app/components/branding/branding.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ <h1 class="mat-h1 branding-page-header">Branding</h1>
2525
data-testid="custom-domain-input"
2626
angulartics2On="change"
2727
angularticsAction="Company: custom domain is edited"
28+
(change)="posthog.capture('Company: custom domain is edited')"
2829
placeholder="e.g. {{companyCustomDomainPlaceholder}}"
2930
[readonly]="currentUser.role === 'DB_ADMIN' || isCustomDomain"
3031
[(ngModel)]="companyCustomDomainHostname">
@@ -95,6 +96,7 @@ <h1 class="mat-h1 branding-page-header">Branding</h1>
9596
data-testid="custom-tab-title-input"
9697
angulartics2On="change"
9798
angularticsAction="Company: tab title domain is edited"
99+
(change)="posthog.capture('Company: tab title domain is edited')"
98100
placeholder="e.g. {{company.name}}"
99101
[readonly]="currentUser.role === 'DB_ADMIN'"
100102
[(ngModel)]="companyTabTitle">

0 commit comments

Comments
 (0)