Using Custom Variables and Value Piping in Surveys

Custom variables and value piping let you personalize your surveys and create more relevant follow-up questions for your visitors.

With these features, you can:

  • Insert dynamic values (like a visitor’s name or a coupon code)
  • Reuse answers from earlier survey questions later in the survey

Using Custom Variables

Custom variables allow you to insert dynamic values into your survey text using the {{ }} syntax.

Example survey text:

Hey {{name}}, can you help us for a moment?

Define the variable on your site before the survey loads:

<script>

  CE2.SURVEY_VARIABLES = {

    name: "John"

  };

</script>

When the survey appears, {{name}} is replaced with the value you provided.

Using Functions as Variables

Variable values can be strings or functions. Functions are useful when the value should be generated dynamically.

<script>

  CE2.SURVEY_VARIABLES = {

    weekday: function () {

      var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

      return days[new Date().getDay()];

    }

  };

</script>

Value Piping: Reusing Survey Responses

Value piping lets you reference answers from earlier questions and reuse them later in the survey.

Example:

Can you tell us why you selected {{question(0).response}}?

Question Numbering (Important)

Survey questions use zero-based numbering:

  • question(0) → first question
  • question(1) → second question
  • question(2) → third question

This applies to all question references.

Referencing Question Data

You can reference different properties of a question, including:

  • Response: {{question(0).response}}
  • Title: {{question(0).title}}
  • Type: {{question(2).type}}

Shortcut References

Crazy Egg also provides shortcuts for common value-piping scenarios.

  • Specific question response:
    {{#1.response}} (second question)
  • Current question:
    {{&.title}}
  • Previously answered question:
    {{<.response}}

Combining Variables and Value Piping

Custom variables and value piping can be used together in the same question.

Example:

{{name}}, you mentioned “{{question(0).response}}”. Can you tell us more?

Best Practices

  • Define CE2.SURVEY_VARIABLES before the survey is shown
  • Double-check question numbers if you reorder your survey
  • Only reference questions that appear earlier in the survey flow
  • Keep personalization simple and easy to read

Troubleshooting

If variables don’t render correctly:

  • Confirm the variable name matches exactly (case-sensitive)
  • Ensure the script runs before the survey loads

If piped values are empty:

  • Make sure the referenced question was already answered
  • Confirm you’re using the correct question number (starting at 0)
Was this article helpful?

Related Articles

Submit a request