Angular Quick Start
This tutorial demonstrates how to integrate Journium with your Angular application.
Setup
Set up Journium for your Angular application.
Install @journium/angular
The Journium Angular SDK gives you access to a JourniumService, Angular module, and provider functions to send events from your Angular application and get insights from your data.
Run the following command to install the SDK:
npm i @journium/angularSet your Journium Publishable Key
-
Sign up for a Journium account for free at journium.app/signup
-
Create an application in your Journium dashboard
-
Copy your Publishable Key from the Developers | API Keys section
Dashboard URLs automatically navigate to your app - just click!
-
Add your key to
src/environments/environment.ts:src/environments/environment.ts export const environment = { production: false, journiumPublishableKey: 'your_publishable_key_here', };Development instances use
pk_test_keys. Production keys start withpk_live_.
Initialize Journium in your app
The Journium Angular SDK supports both standalone (Angular 15+) and NgModule patterns.
Add provideJournium() to your bootstrapApplication call in src/main.ts:
import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import { provideJournium, withJourniumRouter } from '@journium/angular';
import { environment } from './environments/environment';
import { AppComponent } from './app/app.component';
import { routes } from './app/app.routes';
bootstrapApplication(AppComponent, {
providers: [
provideJournium({
publishableKey: environment.journiumPublishableKey,
}),
provideRouter(routes),
// Optional: automatically track pageviews on each route change
withJourniumRouter(),
],
});Import JourniumModule.forRoot() in your root AppModule:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { JourniumModule } from '@journium/angular/ngmodule';
import { environment } from '../environments/environment';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
JourniumModule.forRoot({
publishableKey: environment.journiumPublishableKey,
}),
],
bootstrap: [AppComponent],
})
export class AppModule {}Use JourniumService in your components
Inject JourniumService to track events anywhere in your app:
import { Component } from '@angular/core';
import { JourniumService } from '@journium/angular';
@Component({
selector: 'app-home',
standalone: true,
template: `
<button (click)="handleClick()">Track Event</button>
`,
})
export class HomeComponent {
constructor(private journium: JourniumService) {}
handleClick(): void {
this.journium.track('button_clicked', {
page: 'home',
button_text: 'Track Event',
});
}
}Run the Development Server
Start your application:
ng serveUsing a custom port? Pass --port 4200 to the serve command. The default Angular port is 4200.
Verify Your Setup
Open http://localhost:4200 in your browser. Interact with your app to generate events.
Send Events to Journium
Navigate around your app to automatically send events to Journium.
Then view your collected events at Developers | Events.
Success indicator: You should see events appearing in your dashboard within a few seconds.
Generate Your First Insight
When you create an app in Journium, a default Insight Tracker is automatically created. This tracker helps you test data ingestion and insight generation.
- Go to your Developers | Insight Trackers page
- Click the
Analyze nowbutton for the tracker titled "User Engagement" - Monitor the job status in Developers | Jobs
- Wait for the job to complete (usually takes 1-2 minutes)
- View your generated insights at Dashboard | Insights
Done
Congratulations! You've successfully created your first insight with Journium!
Troubleshooting
What's next?
How is this guide?
Last updated on