# Trigger Conversions with GTM

You can follow these detailed steps to set up Google Tag Manager (GTM) to trigger a Programmatic Conversion when a conversion event happens. This setup will involve creating triggers, tags, and potentially variables in GTM.

## Step 1: Define the Conversion Event in GTM

First, you must define what constitutes a "conversion" in your context. This could be a page visit, form submission, button click or any other user interaction.

## Step 2: Create a Trigger for the Conversion Event

1. **Go to Google Tag Manager Dashboard.**
2. **Click on 'Triggers' in the left sidebar.**
3. **Click 'New' to create a new trigger.**
4. **Set up the trigger:**
   * Choose a trigger type that matches your conversion event. For example, choose "Form Submission" for form submissions or "Click" for button clicks.
   * Configure the trigger with the necessary filters to capture your conversion event accurately. For example, if it’s a button click, you might need to specify certain button properties (like the button's ID or text).

## Step 3: Create a Custom JavaScript Tag

1. **Go to 'Tags' in the GTM dashboard and click 'New'.**
2. **Click 'Tag Configuration' and choose 'Custom HTML'.**
3. **Enter the custom JavaScript code:**

   ```html
   <script>
   // Call your custom function with the appropriate conversion ID
   optibaseSendConversionEvent('yourUserFriendlyConversionId');
   </script>
   ```

   Replace `'yourUserFriendlyConversionId'` with the actual ID or a variable that dynamically determines the ID based on the context of the conversion.

## Step 4: Add a Trigger to the Tag

1. **In the same 'Tag' configuration screen, click 'Triggering'.**
2. **Select the trigger you created in Step 2.**
3. **Save the tag.**

## Step 5: Test Your Tag

1. **Go back to the GTM main dashboard and click 'Preview'.**
2. **Navigate to your site where the conversion event can be triggered.**
3. **Ensure the tag fires when the event occurs. Check the output in the GTM preview pane to confirm that the custom JavaScript function is being called as expected.**

## Step 6: Publish Changes

Once you are satisfied that the tag is working correctly in the preview mode, go back to GTM:

1. **Click 'Submit' to create a new version.**
2. **Name your version and describe the changes.**
3. **Click 'Publish' to make your changes live.**

This setup ensures that every time the specified conversion event happens, your custom JavaScript function `optibaseSendConversionEvent` is called with the specified `userFriendlyConversionId`. Adjust the conversion ID dynamically using GTM variables if the ID should vary based on the conversion context.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.optibase.io/integrations/google/trigger-conversions-with-gtm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
