Frequently Asked Questions

A curated summary of the top questions asked on our Slack community, often relating to implementation, functionality, and building better products generally.
Statsig FAQs
Brex affirm ea Univision OpenAI Notion Microsoft Cider n26 calendly oliveyoung notino
GENERAL

How can I integrate Statsig with an Angular application?

Date of slack thread: 4/12/24

Anonymous: Hi Statsig Team, We are currently integrating Statsig to manage a feature gate in our Angular application and have been unable to locate documentation detailing the integration process for Angular. Could you please direct us to any available resources or documentation that outlines how to incorporate Statsig with an Angular application? Thank you for your assistance.

Vijaye (Statsig): <@U01RAN2FKJP>; Statbot: Click below to mark as resolved.

tore (Statsig): We dont have any angular documentation at the moment, but I think it would end up looking something like this: (refer to js documentation as well)

  1. After installing from npm or yarn, Create a service in Angular that will handle the initialization and provide methods to interact with Statsig:
// src/app/statsig.service.ts
import { Injectable } from '@angular/core';
import Statsig from 'statsig-js';

@Injectable({
  providedIn: 'root',
})
export class StatsigService {
  private initialized = false;

  async initializeStatsig() {
    await Statsig.initialize('client-sdk-key', {
      userID: 'some_user_id'
    }, {
      environment: { tier: 'staging' }  // optional configuration
    });
    this.initialized = true;
  }

  checkGate(gateName: string): boolean {
    if (!this.initialized) {
      console.error('Statsig has not been initialized');
      return false;
    }
    return Statsig.checkGate(gateName);
  }

  getConfig(configName: string) {
    if (!this.initialized) {
      console.error('Statsig has not been initialized');
      return null;
    }
    return Statsig.getConfig(configName);
  }

  // Additional methods like logEvent, getLayer, etc., can be added similarly
}
  1. Ensure Statsig is initialized before the Angular application becomes interactive. Use Angular’s APP_INITIALIZER token:
// src/app/app.module.ts
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { StatsigService } from './statsig.service';

export function initializeStatsig(statsigService: StatsigService) {
  return (): Promise<void> => {
    return statsigService.initializeStatsig();
  };
}

@NgModule({
  declarations: [
    // your components here
  ],
  imports: [
    // other modules here
  ],
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: initializeStatsig,
      deps: [StatsigService],
      multi: true,
    },
  ],
  bootstrap: [/* your root component */]
})
export class AppModule { }
  1. Now, you can inject the StatsigService into any of your Angular components and use it to check gates, get configurations, etc.
// src/app/your-component/your-component.component.ts
import { Component, OnInit } from '@angular/core';
import { StatsigService } from '../statsig.service';

@Component({
  selector: 'app-your-component',
  templateUrl: './your-component.component.html',
  styleUrls: ['./your-component.component.css']
})
export class YourComponent implements OnInit {

  constructor(private statsigService: StatsigService) { }

  ngOnInit(): void {
    if (this.statsigService.checkGate('new_homepage_design')) {
      console.log('Feature is enabled');
    } else {
      console.log('Feature is disabled');
    }
  }
}

This will ensure that the sdk is initialized before your app is fully interactive, and makes an easy way to access statsig gates/experiments in your components.

Anonymous: <@U01RAN2FKJP>, Thank you for your assistance! I appreciate your help.

Statbot: This thread has been marked as resolved. Press below to re-open.

Join the #1 experimentation community

Connect with like-minded product leaders, data scientists, and engineers to share the latest in product experimentation.

Try Statsig Today

Get started for free. Add your whole team!

What builders love about us

OpenAI OpenAI
Brex Brex
Notion Notion
SoundCloud SoundCloud
Ancestry Ancestry
At OpenAI, we want to iterate as fast as possible. Statsig enables us to grow, scale, and learn efficiently. Integrating experimentation with product analytics and feature flagging has been crucial for quickly understanding and addressing our users' top priorities.
OpenAI
Dave Cummings
Engineering Manager, ChatGPT
Brex's mission is to help businesses move fast. Statsig is now helping our engineers move fast. It has been a game changer to automate the manual lift typical to running experiments and has helped product teams ship the right features to their users quickly.
Brex
Karandeep Anand
President
At Notion, we're continuously learning what our users value and want every team to run experiments to learn more. It’s also critical to maintain speed as a habit. Statsig's experimentation platform enables both this speed and learning for us.
Notion
Mengying Li
Data Science Manager
We evaluated Optimizely, LaunchDarkly, Split, and Eppo, but ultimately selected Statsig due to its comprehensive end-to-end integration. We wanted a complete solution rather than a partial one, including everything from the stats engine to data ingestion.
SoundCloud
Don Browning
SVP, Data & Platform Engineering
We only had so many analysts. Statsig provided the necessary tools to remove the bottleneck. I know that we are able to impact our key business metrics in a positive way with Statsig. We are definitely heading in the right direction with Statsig.
Ancestry
Partha Sarathi
Director of Engineering
We use cookies to ensure you get the best experience on our website.
Privacy Policy