Online Booking Analytics Snippet

Overview

The Online Booking Analytics snippet is a powerful feature in Udio's Customer Accounts Settings that allows you to track and analyze booking completion events using custom analytics scripts. This field enables you to integrate with analytics platforms like Google Analytics, Facebook Pixel, or other tracking services when customers complete their enrollment.

How It Works

When a customer successfully completes their booking enrollment, Udio renders the content you've entered in the "Online Booking Analytics snippet" field as part of the thank-you page. The content is processed as a Django template with access to the booking data, allowing you to create dynamic analytics events based on the actual bookings made.

Field Location: Customer Accounts Settings → Online Booking Analytics snippet

Template Context: purchases and bookings objects are available

Template Context Variables

purchases (List of Purchase objects)

Represents the regular bookings created during enrollment. Each person enrolled gets one Purchase object.

Key Purchase Fields:

  • id - Unique purchase identifier
  • person - The Person object for this purchase
  • person.short_name - Person's first name or preferred name
  • person.long_name - Person's full name
  • person.date_of_birth - Person's birth date (if provided)
  • billingaccount - The billing account associated with this purchase
  • facility - The facility where classes take place
  • facility.name - Name of the facility
  • start_date - When the purchase/enrollment starts
  • cancelled_at - Null if active, datetime if cancelled

Example Usage:

django Number of people enrolled: {{ purchases|length }} {% for purchase in purchases %} - {{ purchase.person.long_name }} at {{ purchase.facility.name }} {% endfor %}

bookings (List of Booking objects)

Represents individual session bookings. For a weekly class, this includes all future sessions (typically 13 weeks worth).

Key Booking Fields:

  • id - Unique booking identifier
  • person - The Person object for this booking
  • session - The specific session being booked
  • session.start_at - When the session starts (datetime)
  • session.start_date - Session date in facility timezone
  • session.start_time - Session start time in facility timezone
  • session.course - The course/class being booked
  • session.course.name - Name of the course
  • session.facility - The facility where the session takes place
  • has_attended - Boolean indicating attendance (False for future bookings)
  • cancelled_at - Null if active, datetime if cancelled
  • is_returning_customer - Boolean indicating if this is a returning customer
  • is_first_at_facility - Boolean indicating if this is their first booking at this facility
  • is_first_session_on_course - Boolean indicating if this is their first session in this course

Example Usage:

django Total sessions booked: {{ bookings|length }} {% for booking in bookings %} - {{ booking.session.course.name }} on {{ booking.session.start_date }} {% endfor %}

Analytics Script Examples

Basic Google Analytics 4 (gtag) Example

<script>
  if (typeof gtag !== 'undefined') {
    gtag('event', 'booking_complete', {
      'event_category': 'enrollment',
      'booking_count': {{ purchases|length }},
      'session_count': {{ bookings|length }},
      'value': {{ purchases|length|floatformat:2 }}
    });
  }
</script>

Google Tag Manager DataLayer Example

<script>
  if (typeof dataLayer !== 'undefined') {
    dataLayer.push({
      'event': 'bookingComplete',
      'bookingQtyCount': {{ purchases|length }},
      'sessionCount': {{ bookings|length }},
      'facilityNames': [{% for purchase in purchases %}'{{ purchase.facility.name|escapejs }}'{% if not forloop.last %}, {% endif %}{% endfor %}],
      'courseNames': [{% for booking in bookings %}'{{ booking.session.course.name|escapejs }}'{% if not forloop.last %}, {% endif %}{% endfor %}]
    });
  }
</script>

Advanced Example with Customer Type Detection

<script>
  if (typeof dataLayer !== 'undefined') {
    {% for purchase in purchases %}
      {% with first_booking=purchase.bookings.first %}
        dataLayer.push({
          'event': 'bookingComplete',
          'bookingId': '{{ purchase.id }}',
          'customerId': '{{ purchase.person.id }}',
          'customerName': '{{ purchase.person.short_name|escapejs }}',
          'customerType': {% if first_booking.is_returning_customer %}'returning'{% else %}'new'{% endif %},
          'firstAtFacility': {{ first_booking.is_first_at_facility|yesno:"true,false" }},
          'firstOnCourse': {{ first_booking.is_first_session_on_course|yesno:"true,false" }},
          'facilityName': '{{ purchase.facility.name|escapejs }}',
          'startDate': '{{ purchase.start_date|date:"Y-m-d" }}',
          'sessionCount': {{ purchase.bookings.count }},
          'value': 1
        });
      {% endwith %}
    {% endfor %}
  }
</script>

Facebook Pixel Example

<script>
  if (typeof fbq !== 'undefined') {
    fbq('track', 'Purchase', {
      value: {{ purchases|length }},
      currency: 'USD',
      content_ids: [{% for purchase in purchases %}'{{ purchase.id }}'{% if not forloop.last %}, {% endif %}{% endfor %}],
      content_type: 'booking',
      num_items: {{ purchases|length }}
    });
  }
</script>

Distinguishing New vs Returning Customers

<script>
  {% for purchase in purchases %}
    {% with first_booking=purchase.bookings.first %}
      if (typeof dataLayer !== 'undefined') {
        dataLayer.push({
          'event': {% if first_booking.is_returning_customer %}'returningCustomerBooking'{% else %}'newCustomerBooking'{% endif %},
          'customerId': '{{ purchase.person.id }}',
          'facilityName': '{{ purchase.facility.name|escapejs }}',
          'courseName': '{{ first_booking.session.course.name|escapejs }}',
          'sessionCount': {{ purchase.bookings.count }}
        });
      }
    {% endwith %}
  {% endfor %}
</script>

Important Template Syntax Notes

Since this field uses Django template syntax, remember:

  1. Variables: Use {{ variable_name }} for output
  2. Loops: Use {% for item in list %}...{% endfor %}
  3. Conditionals: Use {% if condition %}...{% endif %}
  4. JavaScript Safety: Use |escapejs filter for text that goes into JavaScript strings
  5. Filters: Common filters include |length , |date:"Y-m-d" , |yesno:"true,false"

Error Handling

If your template contains syntax errors or references non-existent fields, Udio will:

  1. Not break the enrollment flow - the booking will still complete successfully
  2. Check error message if the template fails to render Django error message will be output as a comment in the html file, after the place where template should be rendered

Error Prevention Tips:

  • Test your scripts with simple implementations first
  • Use conditional checks: {% if purchases %}...{% endif %}
  • Wrap JavaScript in try-catch blocks for additional safety
  • Use the |default:"fallback" filter for optional fields

Testing Your Implementation

  1. Start Simple: Begin with a basic implementation like the gtag example above
  2. Check Browser Console: Look for JavaScript errors or network requests to your analytics platform
  3. Verify Data: Use your analytics platform's real-time reporting to confirm events are being received
  4. Test Edge Cases: Try with different numbers of people, courses, and facilities

Common Use Cases

  • E-commerce Tracking: Track bookings as purchases in Google Analytics or Facebook
  • Customer Segmentation: Differentiate between new and returning customers
  • Facility Performance: Track which facilities generate the most bookings
  • Course Popularity: Monitor which courses are most frequently booked
  • Seasonal Analysis: Use booking dates to analyze seasonal trends
  • Revenue Attribution: Connect bookings to marketing campaigns

Best Practices

  1. Always check if analytics objects exist before using them
  2. Use meaningful event names that align with your analytics strategy
  3. Include relevant context like facility names, course names, and customer types
  4. Keep scripts lightweight to avoid impacting page load times
  5. Test thoroughly in a staging environment before deploying to production
  6. Document your implementation for future reference and team members

Data Privacy Considerations

When implementing analytics tracking:

  • Ensure compliance with privacy regulations (GDPR, CCPA, etc.)
  • Avoid sending personally identifiable information unnecessarily
  • Consider using hashed or anonymized customer identifiers
  • Respect user consent preferences for analytics tracking
  • Review your privacy policy to ensure analytics tracking is disclosed

This powerful feature enables deep integration between Udio's booking system and your analytics infrastructure, providing valuable insights into customer behavior and business performance.