Capture Custom Data on GoConnect

Overview

Often, you would like to capture additional data from your audience via the GoConnect widget for your events or competitions.
This guide will show you how to setup custom inputs on your GoConnect widget.

First thing first, navigate to the GoConnect management screen – Aggregate > GoConnect, select your favourite GoConnect widget.

When you are on your GoConnect widget, click “Configure” tab, and choose a template where you would like to add your own custom input fields.

Adding Custom fields

GoConnect accepts input fields that are prefixed with “custom-data-” and followed by the name of the input field.
Note: The name of the input field must contain alphanumeric or underscore characters only.

e.g custom-data-gender is correct,
custom-data-your-gender is incorrect.

See following sample code, which captures Company, Gender and About from the audience

    
<div class="row">
	<div class="col-md-12">
		<div class="st-form-group">
			<label>Company</label>
			<input type="text" class="st-form-control" name="custom-data-company" value="" placeholder="Company" />
		</div>
	</div>
</div>
<div class="row">
	<div class="col-md-12">
		<div class="st-form-group">
			<label>Gender</label>
			<select name="custom-data-gender" class="st-form-control">
				<option></option>
				<option value="male">Male</option>
				<option value="female">Female</option>
			</select>
		</div>
	</div>
</div>
<div class="row">
	<div class="col-md-12">
		<div class="st-form-group">
			<label>Tell us more about yourself</label>
			<textarea name="custom-data-more_about_yourself" class="st-form-control"></textarea>
		</div>
	</div>
</div>
    

Save your settings to see additional fields appear on your GoConnect widget.

When content come through from your GoConnect widget, your custom input will be captured in the “__external_data” column on the Stackla Tile object.

    // Tile Object
    {
        ...
        "__external_data": {
            "_id": { "$id": "123" }
            "firstname": "John",
            "lastname": "Smith",
            "email": "John.Smith@stackla.com",
            "ip": "0.0.0.0",
            "terms_and_conditions_url": "http://your-t-and-c.com",
            "terms_and_conditions": 1,
            "company": "Stackla",
            "gender": "Male",
            "more_about_yourself": "I love Stackla"
        },
        ...
    }

Custom validation

Now that you have added your custom input fields, It’s time to add some validation to those input fields.
By default, your custom input will be validated against our server by the following rules:

  • Field name must not exceed 1024 characters
  • Input value must not exceed 1024 characters
  • Input must not contain HTML elements

However, You can also provide your own validation by adding a callback in the Custom JS tab

    
        window.Stackla.GoConnectCallbacks = {
            onBeforeSave: function (formData, errorMessagesFromServer) {

                if (typeof(formData['custom-data-company']) !== 'undefined' && !formData['custom-data-company']) {

                    errorMessagesFromServer['custom-data-company'] = 'Hey, please enter a company!';

                    return false;

                } else {

                    return true;

                }

            }
        };
    

Note the callback onBeforeSave will be passed with 2 parameters when the beforeSave event is fired.

  • formData is the data to be sent to Stackla for validation before save happens.
  • errorMessagesFromServer is an error object Stackla server returns when data is validated by Stackla.
    If you would like to add your own validation logic,
    simply adding for modifying this object.
  • Remember to return true or false from your callback to indicate whether or not to go ahead with saving the data to Stackla

Returning Custom Data from Stackla

In Stackla, we take security seriously, custom inputs from your GoConnect widget will be hidden from all Stackla public endpoints.

However, there are some situations where you would like certain input to be exposed to the public, for example, you are capturing “company” from your GoConnect widget,
and you want “company” data to be displayed on your widget.
You can achieve this by adding data-permission=”public” to your “company” input on the GoConnect widget prior to your GoConnect widget go live.

    <input type="text" name="custom-data-company" value="" data-permission="public" />

When you adding data-permission=”public” data attribute to your custom inputs, you indicate to the GoConnect widget that these fields will be exposed to the public.
Stackla will capture your public data in the external_data column on your Stackla Tile object.

    // Tile Object
    {
        ...,
        "external_data": {
            "company": "Stackla"
        }
        ...,
    }


    // Custom Widget JS - Display "company" data on your Widget
    Callbacks.prototype.onCompleteJsonToHtml = function (tileObject, t) {
        if (t && t.external_data && t.external_data.company) {
            tileObject.append(t.external_data.company);
        }
        return tileObject;
    };

Note that you can find your public data in the external_data column on the Stackla Tile Object, external_data is a subset of the __external_data column.
__external_data on the other hand is private and it is hidden from all public endpoints by default, you can only access it on Moderation View or from Stackla API

Want to stay up to date with all the latest Stackla developer news? Sign up!