Skip to content
Home » Blog » How Do I Capture the GCLID Parameter & Store as Hidden Square Space Field?

How Do I Capture the GCLID Parameter & Store as Hidden Square Space Field?

To capture the Google Click Identifier (gclid) parameter and store it as a hidden field on a Squarespace form, you can use the following steps:

  1. Add a hidden field to your Squarespace form:
  • In the Squarespace editor, go to the page where your form is located.
  • Click on the form block to edit it.
  • Add a new field to the form and choose “Hidden Field” as the field type.
  • Enter a name for the field, such as “gclid”.
  • Leave the field value blank for now.
  • Save the changes to the form.
  1. Create a Google Tag Manager (GTM) tag to capture the gclid parameter:
  • Log in to your GTM account and create a new tag.
  • Select “Custom HTML” as the tag type.
  • Paste the following code into the HTML box:
function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
var gclid = getParameterByName('gclid');
if (gclid) {
    var input = document.querySelector('input[name="gclid"]');
    if (input) {
        input.value = gclid;
  • Replace “gclid” in the script with the name of your hidden field in Squarespace.
  • Save the tag.
  1. Create a trigger to fire the tag on form submission:
  • Create a new trigger in GTM and select “Form Submission” as the trigger type.
  • Under “Fire On”, select “Some Forms” and choose the form where you added the hidden field.
  • Save the trigger.
  1. Publish the changes in GTM:
  • Click on “Submit” in GTM to publish the changes to your site.

Once you have completed these steps, the gclid parameter will be captured by the script when someone submits the form on your Squarespace site. The script will then populate the value of the hidden field with the gclid parameter, which can be viewed in your Squarespace form submissions.