How can I collect current page URL in form?

I am having a problem populating hidden fields when they are hidden, but not when they are normal. I am using javascript to point at the form field like this:

jQuery(‘input[id=“last_known_conversion_page-customnumbersthatidontknowifishouldsharepublicly”]’).val(window.location.href).change();

This javascript works to populate the field when the form field is added in HubSpot’s form editor normally, but it does not work when I check the box to “Make this field hidden” in the HubSpot form editor.

My clunky workaround is to add the field in HubSpot’s form editor as a normal (not hidden) field, but then add display:none that field’s class to my CSS file:

.hs_last_known_conversion_page {
display: none;
}

Doing this does work, and the field populates and passes through. But it’s a hack that I will certainly forget by next year and then won’t be able to figure why fields that aren’t marked as hidden in HubSpot are being hidden.

Is there a better way to be doing this in 2019? I’m not sure if some of the information on this page hasn’t changed in the past couple of years.