<input id="id-{{ widget.name }}" type="hidden" name="{{ widget.name }}" value="{% if widget.default_value %}{{ widget.default_value }}{% endif %}">

<script type="text/javascript">
	window.onload = function() {

    var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = decodeURIComponent(window.location.search.substring(1)),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;

        for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');

            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : sParameterName[1];
            }
        }
    };

		var referralLink = getUrlParameter('ref');
		var referral = localStorage.getItem('{{ widget.name }}Link');

		if (typeof referralLink !== "undefined") {
			localStorage.setItem('{{ widget.name }}Link', referralLink)
		};

		if (typeof referral === "undefined" || referral === null) {
			localStorage.setItem('{{ widget.name }}Link', '{{ widget.default_value }}' ) 
		};
		
		var signUpReferralLink = localStorage.getItem('{{ widget.name }}Link');
		document.getElementById('id-{{ widget.name }}').value = signUpReferralLink;
	}
</script>