Skip to main content

Pass respondent attributes with Google Tag Manager

Use GTM to show Survicate surveys on your website to a chosen Audience

Written by Agnieszka

Website or in-product surveys can be installed on your website in various methods, one of which is Google Tag Manager.

If you're using Google Tag Manager on your website, you can also use it to establish the surveys' Audience, to keep all your code in one place.

Targeting your survey based on respondent attributes lets you:

  • create Audiences to only collect feedback from chosen groups of visitors,

  • target surveys based on demographics, department, or type of company someone works in,

  • filter your surveys' answers for better respondent sampling and analysis.

In this article, we'll guide you step-by-step through using GTM to passing respondent attributes to Survicate, and using them to target the surveys.

Please note that this feature is available on some of our subscription plans. Reach out to us at support@survicate.com to learn more about the pricing.

Install Survicate on your website

We described how to add the Survicate tracking code via GTM to your website in this guide.

Please follow the steps outlined there, and then you'll be able to continue setting up respondent attributes.

Pass attributes through Google Tag Manager

To collect and use attributes, you need to paste an additional code right before the regular Survicate tracking code on your website.

To do this:

1. Open the HTML tag with the Survicate tracking code in Google Tag Manager.

2. In this tag, modify the code to include additional JavaScript, responsible for passing user attributes to Survicate.

Your attributes, in this form:

// Define attributes before initializing Survicate

(function(opts) {
opts.traits = {
"user_id": "Your user ID here",
"company_name": "Value here",
"subscription_status": "Value here",
"signed_up": "Value here"
};
})(window._sva = window._sva || {});

/// Your tracking code goes here

should be included in the Survicate tracking code like this:

More information about the JavaScript methods can be found in our documentation for developers.

💡 If you plan to use the Users audience (backend targeting), make sure you also pass a unique user_id attribute for each respondent, for example user_id=12345.

3. The GTM tag with the above code should be triggered in Google Tag Manager by any trigger of your choice, to initialize the Survicate code and show a survey.

Set up the Audience in your survey

You can use the Attributes filter in two Audience types:

  • Visitors (frontend targeting): we store respondent IDs locally in the browser. If someone visits from a different browser or device, we won’t recognize them.

  • Users (backend targeting): we store respondent IDs on our servers, so we recognize users regardless of the device or browser they use. This requires a user_id attribute.

📌 In a Manual audience (CSV upload), only the user_id column is used for targeting. The other attributes from your file won’t target the survey, but you can see them and filter by them in the Analyze tab.

To learn more about each Audience type, check out Set up an Audience for your Website or in-product survey.

1. Go to the Audience tab of your Website or in-product survey.

2. Click +Add audience and choose the audience type.

3. Click Add filter and pick Attributes under User properties:

4. Pick whether you'd like to include or exclude the visitors with a specific attribute:

5. Type in the attribute name, select the operator, and add the attribute value(s).

💡 For example, to target visitors from small companies (up to 50 employees), set company_size to equal 50. If the attribute has already been passed to Survicate before, you'll find it in the drop-down list:

To target visitors who simply have a certain attribute, no matter its value (e.g. purchase_id for anyone who bought from you), select has any value:

All the operators you can select here:

and the data types they support

  • equals (string, numbers)

  • does not equal (string, numbers)

  • is greater than / is greater than or equal (numbers)

  • is less than / is less than or equal (numbers)

  • is between / is not between (numbers) - includes the starting and ending number

  • contains / does not contain (string)

  • is true / is false (boolean)

  • earlier than / later than / on the date (date)

  • is between dates / is not between dates (date) - includes the starting and ending date

  • has any value (all data types)

  • more than / less than (days / hours) ago (numbers)

For equals, does not equal, contains, and does not contain, you can add multiple values:

We support these data types in attribute values: string, numbers (integers and decimals, positive and negative), boolean, and date.

You can add up to 50 attributes to a filter.

❗️The limit of how many attributes can be passed to one Survicate workspace for all survey types altogether is 2,000.

❗️To keep things safe and privacy-friendly, do not include any personal data (e.g. name, email, contact details) and specifically any special personal data (e.g. health data, political opinions) - if you include them in the attributes which are used for survey targeting, you are taking the risk of respondents' data being visible to unauthorized parties. It’s better to stick with general data: user types, subscription plans, or broad demographics.

❗️ Attribute and attribute value names are case-sensitive. If there is any discrepancy between the name of the attribute you send to Survicate via GTM and the Survicate panel, the Audience will not work properly.

6. If you have two or more attributes in the same audience, decide if we should trigger the survey when all of them match the visitor (AND condition) or only one of them (OR condition):

7. Once your audience is ready, click Create audience and enable it to display the survey correctly:

Use multiple Audiences

If you have two or more audiences enabled, we trigger the survey to all enabled audiences. The website visitor must match the requirements of at least one of the enabled audiences (OR condition).

📌 A survey can use only one targeting type, either frontend or backend. You can’t combine a Visitors audience with other Audience types. Users and Manual audience can be combined with each other.

💡 If two surveys target the same website or app, and one uses frontend targeting while the other uses backend targeting, the frontend survey shows first.

For Users and Manual audience targeting, we recommend using a secret key and a user key for extra security. Read here how to set it up.

Filter results by respondent attributes

The respondent attributes passed via Google Tag Manager are also included in the Analyze tab of the survey.

1. Go to the Analyze tab of your survey, click Filter, and you'll see your Custom attributes to choose from:

❗️The attribute will be available as a filter after the survey receives at least one response with this attribute.

You cannot apply filters in the Overview tab.

2. You can also see the attribute with its value in Analyze ➡️ Individual responses, next to the respondent's answers:

Troubleshooting

I don't see the survey even though I match the respondent attributes

Check that the GTM tag with your attributes fires before the Survicate tracking code and that attribute names match exactly. If you have already answered the survey, try changing its frequency settings or test in incognito mode.

📞 If you have any questions about triggering a survey with Google Tag Manager, please reach out to us at support@survicate.com or strike up a chat conversation 👉

Did this answer your question?