import { MdxImage } from "@/components/MdxImage";

import I1 from "./images/I1.webp";
import I2 from "./images/I2.webp";

export const metadata = {
  title: "Using Actions in Formbricks | Fine-tuning User Moments",
  description:
    "Dive deep into how actions in Formbricks help products and organizations to engage users at precise moments in their journey. Discover the power of actions, from coding to no-code setups, to refine user targeting and generate richer, more detailed user insights.",
};

#### App Surveys

# Actions & Targeting

Understanding user thoughts and feelings at critical moments in their journey is pivotal. To achieve this, Formbricks uses user-centric actions that trigger surveys at precisely the right time. Actions are essentially notifications sent from your application to Formbricks when predefined user activities occur, making it possible to gather insights during key interactions.

<Note>
  Ensure that you’ve **initialized Formbricks with a userId** to fully utilize this feature along with other
  app survey capabilities.
</Note>

## **How Do Actions Work?**

Actions in Formbricks App Surveys are deeply integrated with user activities within your app. When a user performs a specified action, the Formbricks widget detects this activity and can present a survey to that specific user if the trigger conditions match of that survey, while also recording the event. This capability ensures that surveys are not only triggered at the right time but are also tailored to the user’s recent interactions within the app. You can set up these actions through a user-friendly No-Code interface within the Formbricks dashboard.

## **Why Are Actions Useful?**

Actions are invaluable for enhancing survey relevance and effectiveness:

- **Personalized Engagement**: Surveys triggered by user actions ensure content is highly relevant and engaging, matching each user’s current context.
- **User Attributes**: By tying surveys to specific user attributes, such as activity levels or feature usage, you can customize the survey experience to reflect individual user profiles.
- **User Segments**: Analyze action data to create detailed user segments, targeting specific groups with surveys that are pertinent to their behaviors or interactions within the app.
- **User Targeting**: Precise targeting based on user actions and attributes ensures that surveys are shown only to users who meet certain criteria, enhancing the relevance and effectiveness of each survey.

## **Setting Up No-Code Actions**

Formbricks offers an intuitive No-Code interface that allows you to configure actions without needing to write any code.

To add a No-Code Action:

1. Visit the Formbricks Dashboard & switch to the Actions tab:

<MdxImage
  src={I1}
  alt="setup checklist ui of survey popup for app surveys"
  quality="100"
  className="max-w-full rounded-lg sm:max-w-3xl"
/>

2. Now click on “Add Action”

<MdxImage
  src={I2}
  alt="setup checklist ui of survey popup for app surveys"
  quality="100"
  className="max-w-full rounded-lg sm:max-w-3xl"
/>

Here are four types of No-Code actions you can set up:

### **1. Click Action**

Click Action is triggered when a user clicks on a specific element within your application. You can define the element's inner text or CSS selector to trigger the survey.

- **Inner Text**: Checks if the innerText of a clicked HTML element, like a button label, matches a specific text. This action allows you to display a survey based on text interactions within your application.

- **CSS Selector**: Verifies if a clicked HTML element matches a provided CSS selector, such as a class, ID, or any other CSS selector used in your website. It enables survey triggers based on element interactions.

### **2. Page view Action**

This action is triggered when a user visits a page within your application.

### **3. Exit Intent Action**

This action is triggered when a user is about to leave your application. It helps capture user feedback before they exit, providing valuable insights into user experiences and potential improvements.

### **4. 50% Scroll Action**

This action is triggered when a user scrolls through 50% of a page within your application. It helps capture user feedback at a specific point in their journey, enabling you to gather insights based on user interactions.

This action is triggered when a user visits a specific page within your application. You can define the URL match conditions as follows:

<Note>
You can combine the url filters with any of the no-code actions to trigger the survey based on the URL match conditions.

### **URL Match Conditions**

- **exactMatch**: Triggers the action when the URL exactly matches the specified string.
- **contains**: Activates when the URL contains the specified substring.
- **startsWith**: Fires when the URL starts with the specified string.
- **endsWith**: Executes when the URL ends with the specified string.
- **notMatch**: Triggers when the URL does not match the specified condition.
- **notContains**: Activates when the URL does not contain the specified substring.

</Note>

## **Setting Up Code Actions**

For more granular control, you can implement actions directly in your codebase:

1. **Configure the Action**: First, add the action via the Formbricks web interface to make it available for survey configuration.
   After that you can fire an action using `formbricks.track()`

2. **Track an Action**: Use formbricks.track() to send an action event to Formbricks.

<Col>
<CodeGroup title="Track an action">

```javascript
formbricks.track("Action Name");
```

</CodeGroup>
</Col>
Here is an example of how to fire an action when a user clicks a button:
<Col>
<CodeGroup title="Track Button Click">

```javascript
const handleClick = () => {
  formbricks.track("Button Clicked");
};

return <button onClick={handleClick}>Click Me</button>;
```

</CodeGroup>
</Col>

This documentation frames actions around user interactions, emphasizing the connection between the user's activities and the survey experience. By leveraging user-centric actions, you can create highly targeted and timely surveys that resonate with users and yield valuable insights.
