# Google Tag Manager

Google Tag Manager (GTM) provides an easy way to add tags and triggers. It requires little to no coding to setup Blitzllama and can be deployed in minutes. Once [`Blitzllama Tag`](https://tagmanager.google.com/gallery/#/owners/Blitzllama/templates/blitzllama-gtm-tag) is integrated with GTM you will be able to create users, add user attributes and launch surveys.

### Installing Blitzllama tag with GTM

### Step 1: Initialise Bltizllama Tag

* Open the Google Tag Manager app and click on **Tags** Tab.
* Click on **new** Tag and click on Tag Configuration section. Under the "**Discover more tag types in the Community Template Gallery**" option search for  [`Blitzllama Tag`](https://tagmanager.google.com/gallery/#/owners/Blitzllama/templates/blitzllama-gtm-tag)
* Click on Choose Template to add **Blitzllama Tag** to your GTM.
* Copy API\_KEY from `Connections > Web` on the Blitzllama dashboard.
* Under API key section in Blitzllama GTM template paste the copied API\_KEY.

<figure><img src="https://lh6.googleusercontent.com/5jKCxf193hyzSmYED20T_eS6AY_qfEXuFZ0_eAOhmj7GqxaLI3rlSYFeNcufMXlZjQQTtyqa3YtMHuQh4Z2mS23k38mJYPWJr17ve_OUn5qCGf9-FO3i-nYDTidjZu9jV0nzhAMk9K0Xzv01Y8IRkZ1iQYTZKK3_fO-h7P7inXERYL08o1fMZIo9EQ" alt=""><figcaption></figcaption></figure>

<figure><img src="https://lh6.googleusercontent.com/5Cw4Xar7qYttX1xpe-vXIkhWE7Q0fEpKu5kncScFDewWQORdBKuvkrgL0b-iqpO0Ujojev9458hKg_0qt7QusqKUOXXN3CNps5q7A9yVuUbBXZQSb6ZvHxmBasBqykM54Vsj8jT6soNmdAEAEeNsHUFtcDHh_nePp6UklgO9Vq8-wuORWN4m5d0R4A" alt=""><figcaption></figcaption></figure>

### Step 2: Manage users

There are two ways to manage users, you can either assign a unique user\_id to each user or keep the users anonymous.&#x20;

a. Identify users with user\_ids (recommended)&#x20;

* Make sure to set **Action Type** to **User Id**.
* Click on ![plus](https://files.readme.io/f63db7a-brickplus.png), and choose the variable you would wish to use as UserId. Read more about the&#x20;
* Now click on **Triggering** Section, to choose the trigger.
* Select **All Pages** (recommended) or on **Some Pages** as the Trigger.
* Click on **save** button to save the changes to Blitzllama Tag.
* Click **Submit** and then **Publish** to push your changes.

<figure><img src="https://lh4.googleusercontent.com/qBNZVeheuiph8tbTJhux-2byJxkD2a_Ce1lBTwY19HNzxJC0gGy23U5fWG8kCUQFe5A8USC7A2r0QNiyEMS6IZT2q7UUQqfekbGj3NS8XqjxxBzdDC3Kf8_vxIyV1Ig1pddcFs-HwntptP-vlncBbj3MICiPPCGtreL7U3ONQDbihfvqZvV3e18cBg" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Read more about the variables here [GTM variables](https://support.google.com/tagmanager/answer/7683056) and triggers here [Triggering Section](https://support.google.com/tagmanager/answer/7679316).
{% endhint %}

b.  Users are not assigned user\_ids but are anonymously surveyed

* Make sure to set **Action Type** to **Install.**
* Now click on **Triggering** Section, to choose the trigger.
* Select **All Pages** as the Trigger.
* Click on **save** button to save the changes to Blitzllama Tag.
* Click **Submit** and then **Publish** to push your changes.

<figure><img src="https://lh3.googleusercontent.com/Xea4KiegBKSdjAQGHYuWC-4vP239s6Yg5Y3JToi03qJxuzD_JXeLkz-cWl5515GFCeB2URhxoxkX3FHEZsGGyg5bHN8uLd_ST0SKtTxj9ba-J3yz0tZAf82AHqj6zENbt8oh-DwW5Mq3dTWCGeE6DmMQsPwFIM3VBwpSmik8xTsPizD4XaShfFIJzg" alt=""><figcaption></figcaption></figure>

### Step 3: Send User Attribute to Blitzllama (optional)

Adding user attributes will help in understanding user and creating cohorts for targeted surveys.

* Set **Action Type** to **User Attribute**.
* In **Attribute Key** text field, enter the user attribute field name you wish to send to Blitzllama.&#x20;
* In **Attribute Value** field, click on ![plus](https://files.readme.io/f63db7a-brickplus.png), and choose the variable you would want.
* In **Data Type** drop-down, select apt data type (string, number, boolean, date) of the **Attribute Value** variabl&#x65;**.**
* Now click on **Triggering** Section, to choose the trigger.
* Select on appropriate pages or click actions (ensure the attribute value will be available when the tag is fired) as the Trigger.
* Click on **save** button to save the changes to Blitzllama Tag.
* Click **Submit** and then **Publish** to push your changes.

<figure><img src="https://lh3.googleusercontent.com/dgNz9l-LgkGh_Sd-JAp9OjqFVcIyc1nVuGU8GgbDO_RPSZ7GUTl83LE_5HBHlRjFZElxnu2OmmiwvB6szVKjpCV49PjP0gq59HvTw8V66ds5Ur5BMgILdQ58bt_W3A9uCiA-z1dNo8FyQvedHhNju5WuOHIMn5C3bGk0e2Wfkpo3KXv1Gljdu-W41w" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
Ensure user creation Blitzllama Tag is called before User Attribute Tag. Click here to read more on [**Trigger Sequencing**](https://support.google.com/tagmanager/answer/6238868).
{% endhint %}

### Step 4: Setup survey triggers &#x20;

There are two ways to trigger surveys inside your web application.&#x20;

You can also use backend events to launch in-app surveys. Check out for more details.

#### a. Creating triggers on Blitzllama's dashboard

Refer to this section: [creating triggers on the web triggers](https://documentation.blitzllama.com/web#3.-creating-triggers)&#x20;

We suggest creating triggers the above method, instead of triggering surveys via GTM (below section), as it requires a new GTM tag to be created for every trigger.

#### b. Trigger Survey based on GTM triggering (optional)&#x20;

* Set **Action Type** to **Trigger Survey**.
* In **Trigger Name** text field, enter the Trigger Name that is configured on Blitzllama dashboard.&#x20;
* Now click on **Triggering** Section, to choose the trigger.
* Select **All Pages** as the Trigger.
* Click on **save** button to save the changes to Blitzllama Tag.
* Click **Submit** and then **Publish** to push your changes.

{% hint style="success" %}
You can also use **backend events** to launch in-app surveys. Check out <https://documentation.blitzllama.com/connections/backend-trigger> for more details.
{% endhint %}

You are all set to launch your first Blitzllama survey using GTM!

### **DataLayer**

A data layer is a JavaScript object that is used to pass information from your website to your Tag Manager container. You can then use that information to populate variables and activate triggers in your tag configurations. [Click here to read more on DataLayer](https://support.google.com/tagmanager/answer/6164391?hl=en)

```javascript
<!-- Global site tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-YYYYYY"></script>
<script>  
    window.dataLayer = window.dataLayer || [];  
    dataLayer.push({
      'event': 'signup', 
      'username': 'jane doe',
      'age': 25,
      'userid': 'user-123'
    }
</script>
```

**Setting GTM variables to set to DataLayer variable**

* In Google Tag Manager, click **Variables**. Under **User-Defined Variables,** click on **New** Butto&#x6E;**.**
* Enter the appropriate variable name.
* Under **Variable Configuration**, click on choose the variable type and select **Data Layer Variable** option.&#x20;
* In **Data Layer Variable Name** text field, enter data Layer variable you want set as variable.
* Click **Save**.
