DEV Community

Cover image for πŸ”₯ How To Get Juicy User Insights With In-App Pre-Churn Survey In Next.js With Formbricks πŸ’‘πŸ’¬
Olasunkanmi Balogun for Formbricks

Posted on

πŸ”₯ How To Get Juicy User Insights With In-App Pre-Churn Survey In Next.js With Formbricks πŸ’‘πŸ’¬

Churn surveys are a valuable tool for businesses, especially app-based businesses, to understand why customers are leaving their service. By asking customers why they are churning, businesses can identify areas where they can improve their product or service to prevent future churn. An example of such surveys can be seen below:

Image of a churn survey

Imagine being able to anticipate user departures before they happen, giving you a chance to address concerns, tailor your offerings, and ultimately, boost user loyalty. This is where the power of pre-churn surveys comes into play, revolutionizing the way businesses interact with their users.

TL;DR

In this article, you will learn how to get juicy user insights with in-app pre-churn surveys in your Next.js application using Formbricks.

Light bulb gif

Formbricks: The Only Open-Source Solution For Pre-Churn Surveys

Formbricks is an open-source survey software that can help businesses create and send in-app pre-churn surveys. Formbricks is easy to use and integrates with any web, mobile, or desktop application. Support us by giving us a star. πŸ˜‰

How To Craft A Churn Survey With Formbricks

In this section, I will guide you systematically through the process of crafting a churn survey for your application. Here's an overview of the steps we'll cover:

  • Create a complimentary Formbricks cloud account.
  • Construct your churn survey utilizing the Formbricks platform.
  • Seamlessly integrate Formbricks into your application.
  • Put theory into practice by implementing your in-app survey.

1. Create an account on Formbricks - It's Free

When utilizing Formbricks, you have the flexibility to either opt for self-hosting if you prefer, or take the more straightforward path by registering on our platform.

Upon completing the signup process and swiftly navigating through the onboarding procedures, you will find yourself on your dashboard, which will be presented in a layout similar to this:

Formbricks dashboard image

Following this, it's time to construct your churn survey πŸ› οΈ

2. Craft your churn survey

Navigate to your dashboard and select the churn survey template:

Churn survey tab image

You'll be navigated to a page that looks like this:

Churn Survey page

This is your canvas for refining survey questions. Keep in mind that your edits on the left side reflect in real-time in the preview.

Once you've refined the questions to your liking, proceed to the Settings tab adjacent to the Questions tab. This is where you can fine-tune your survey's configuration.

For the "How to Ask" segment, opt for the web app choice, given your intention to integrate it into your web application:

How to ask section

There's a note in orange that hints we haven't connected with our app yet. No sweat! We'll get back to it, let's get our other survey configuration right first!

Another essential aspect within the Settings tab is the Survey Trigger section. As its name implies, this settings is for what will trigger the survey in your app.

Survey trigger section image

When you click on the select field, a dropdown will appear, presenting you with a range of options. In case none of these options align with your preferences, you can introduce a personalized trigger by selecting the "Add action" choice. This will prompt a modal to appear:

Illustration to select out-of-the-box options

From the available options, feel free to make your selection. However, for the context of this article, I'll demonstrate using the inner text option.

Inner text option

Once you've chosen your preference within this modal, proceed to save your choice by clicking the "Track Action" button. Subsequently, revisit the dropdown and select the newly added option.

Now, proceed to click the "Publish" button located in the upper right corner.

This action will direct you to the Summary page, where you'll gain access to your survey analytics. Additionally, you'll receive a prompt to install the Formbricks widget, enabling you to establish a connection between your survey and your application.

Survey analytics image

Click on it to navigate to the setup checklist page.

3. Setup Checklist: Installing The Formbricks Widget

On the setup checklist page, you'll come across a widget status indicator. This indicator informs us whether our application has been linked to Formbricks Cloud or not. Since we haven't yet established the connection at this juncture, you will observe the following display on your screen:

Status indicator image

This is the point where we'll have to get our hands dirty and dive into our app code editor. πŸ˜ƒ πŸš€

I assume you already have your Next.js application up and running, so we're set to hit the ground running!

Note: I'll be using the Next.js pages dir moving forward.

We'll start by installing Formbricks accross our app with the following command:

npm install @formbricks/js --save
Enter fullscreen mode Exit fullscreen mode

Afterwards, navigate to the _app.js component and modify the code as seen below:

import formbricks from "@formbricks/js";
import { useEffect } from "react";
import { useRouter } from "next/router";

if (typeof window !== "undefined") {
  formbricks.init({
    environmentId: "<your environment id>" ,
    apiHost: "https://app.formbricks.com", 
    debug: true,
  });
}

export default function App({ Component, pageProps }) {
  const router = useRouter();

  useEffect(() => {
    // Connect next.js router to Formbricks
    const handleRouteChange = formbricks?.registerRouteChange;
    router.events.on("routeChangeComplete", handleRouteChange);

    return () => {
      router.events.off("routeChangeComplete", handleRouteChange);
    };
  }, []);

  return <Component {...pageProps} />
}

Enter fullscreen mode Exit fullscreen mode

Pay attention to the if statement before the component definition. It makes sure that the widget is only initialized if this component is rendered in a browser.

For this tutorial's sake, the environmentId property has been intentionally omitted. In actual practice, this value is private and unique to each user. You can retrieve your environmentId from Step 2 of the setup checklist page. Copy and paste the value into the appropriate variable as depicted below:

Environmentid image

Following this, the widget status indicator in the Setup checklist page should have been updated to this after reloading your app πŸŽ‰:

Status indicator update

Your web browser's console should also display the following logs, confirming the establishment of the connection:

Console log image

Now that we've verified the connection between your app and Formbricks Cloud, we can proceed to implement the survey trigger.

4. How to trigger the Formbricks pre-churn survey

As a quick reminder, we configured a trigger based on the button's inner text, "Cancel Subscription."

With that in mind, feel free to incorporate the button with the designated inner text wherever you see fit. I'll demonstrate the implementation in my index.js file:

import Head from "next/head";

export default function Home() {
  return (
    <>
      <Head>
        <title>Formbricks Churn Survey</title>
        <meta name="description" content="Generated by create next app" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <main>
        {/* survey trigger */}
        <button>Cancel Subscription</button>
      </main>
    </>
  );
}
Enter fullscreen mode Exit fullscreen mode

On my home page, the survey can now be triggered after clicking the button:

Illustration of survey trigger

Congratulations! You have effectively integrated your churn survey into your app! πŸŽ‰

Furthermore, you have the flexibility to customize the placement and appearance of the survey in your application. To achieve this, navigate to the settings page within your Formbricks account and select the "Look & Feel" option from the sidebar.

As an illustration, if you prefer your survey to appear at the center of your web application, scroll down to the "In-app survey placement" section and opt for the "Centered Modal" choice. After adjusting it to your liking, the modal should now appear like this:

Illustration for centered modal option

If the placement doesn't reflect immediately, try restarting your app. πŸ˜‰

Finally, you can effortlessly access your survey analytics and view responses on the Formbricks platform. Simply click on the survey you've crafted to explore these valuable insights.

Conclusion

So far, you've learnt how to:

  • connect Formbricks Cloud to your app
  • Easily create an in-app Churn Survey with Formbricks
  • How to view your survey analytics on Formbricks

From now on, the world of in-app pre-churn survey is yours. Go ahead and prevent that churn πŸ’ͺ 😁

To help us keep this articles coming, kindly give us a star on Github. πŸ˜‰

Thank you for reading!

Top comments (6)

Collapse
 
jobenjada profile image
Johannes

Super cool, thanks so much for writing this Ola!

Collapse
 
dhruwang profile image
Dhruwang Jariwala

Insightful !! πŸ™ŒπŸ»

Collapse
 
rotimibest profile image
Rotimi Best | ClassroomIO

Very detailed guide, helped me create my first survey πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰.

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

Really well written article @sukodes!

Collapse
 
dumebii profile image
Dumebi Okolo

Way to go, Ola! πŸ₯³

Collapse
 
pandeymangg profile image
Anshuman Pandey

Super cool!