Skip to content

Embed and style a form

Steps for

Add a form to your store

Most Shopify stores should use the SparkLayer Form block. In the theme editor, you pick a form and set common layout and styling options, without adding code.

  1. In the SparkLayer Dashboard, open the form from Forms (opens in your SparkLayer Dashboard in a new tab). Go to the Embed tab and click Open theme editor. Or, in your Shopify admin, go to Online Store,Themes (opens in your Shopify admin in a new tab) and click Customize.
  2. Open the page where you want the form, and add the SparkLayer Form block to a section.
  3. Select the form you want to show.
  4. Adjust the styling options in the block's settings.
  5. Click Save. The form is now on your store.

When you publish changes to the form later, they show on your store straight away.

If your form isn't in the block's dropdown, open the SparkLayer Wholesale app under Sales channels in your Shopify admin and accept any new permissions it asks for.

For more control, use the embed code instead: see the Other platforms tab.

Translate a form

A form's Language setting (on the Settings tab) only translates built-in text, such as buttons and the address lookup. The labels, descriptions and messages you write stay as you wrote them. Forms aren't covered by the Core Script translations either. On Shopify, Translate & Adapt can't translate a form's field labels, because the form loads as an embed.

To show a form in several languages, make one form per language:

  1. At Forms (opens in your SparkLayer Dashboard in a new tab), click More actions next to the form, then Duplicate. Make one copy for each language.
  2. In each copy, rewrite the labels, descriptions, button text and success message in that language, and set its Language if it's listed. See Configure form settings.
  3. Publish each copy.
  4. Copy each form's embed code from its Embed tab (under Another website, Copy code).

Then show each language's form on your store:

These steps are for the B2B login page, with your default language's embed code in its Custom Contact Form HTML setting.

  1. Open Shopify's Translate & Adapt app (opens in a new tab) and choose a language at the top.
  2. Under Theme, click Templates, then select Page: B2B Login.
  3. Find the field Main: Custom Form Html and paste that language's embed code.
  4. Save, then repeat for each language.

Your theme needs a language selector, so customers can switch language and see the right form.

Entries arrive on each copy separately, so check the entries of every language's form.

Style a form

Forms match the rest of SparkLayer on your store automatically, so most stores don't need to change anything.

Shopify only

On Shopify, the SparkLayer Form block also has styling options you can set in the theme editor, without code.

To make forms look different from the rest of SparkLayer, your developer or agency can set CSS variables.

A form is kept apart from your theme's styles (it loads in a "shadow DOM"), so other CSS in your theme or the app embed doesn't reach its fields. Only the --spark-form-* and --spark-* variables do. On Shopify, add them in the theme editor, under Theme settings > Custom CSS.

Code for your developer

Embedded forms use the same core CSS variables as the rest of SparkLayer. If the SparkLayer Core Script already sets --spark-* variables on your storefront, forms pick them up automatically. See Customising the design for your global styles.

To style forms differently from the rest of SparkLayer, set --spark-form-* variables on the spark-form element. Styles are applied in this order of priority:

  1. --spark-form-* form-specific variables
  2. --spark-* global SparkLayer variables
  3. SparkLayer's default styles

For example:

spark-form {
  --spark-form-max-width: 680px;
  --spark-form-button-color: #000000;
  --spark-form-button-raised-background: #000000;
  --spark-form-button-raised-color: #ffffff;
  --spark-form-link-color: #000000;
  --spark-form-border-radius-default: 4px;
}

See Form CSS variables for every variable.

Embed a form manually (for developers)

This section is for your developer or agency, when they add the form by hand or need its options. The embed code has two parts. First, the SparkLayer form script:

<script src="https://cdn.sparklayer.io/spark-form.v1.js"></script>

Then the form itself, placed where you want it to appear:

<spark-form
form-id="your-form-id"
site-id="your-site-id">
</spark-form>

Your site ID is in Account settings.

Embed attributes

AttributeRequiredWhat it does
form-idYesThe ID of the form to show.
site-idYesYour SparkLayer site ID.
site-envNoSet to test to load the form from your test environment. Defaults to live.
entry-idNoResumes an existing entry.
entry-keyNoThe key needed to open an existing entry.
hide-titleNoSet to true to hide the form title.
preview-version-idNoPreviews a specific form version.

Track form analytics (for developers)

Forms send events as a customer moves through them, so you can see in Google Analytics, Google Tag Manager or another analytics tool how many customers open a form, start it and submit it, and where they stop. This works with the SparkLayer Form block on Shopify and with the embed code.

Each event is a CustomEvent dispatched on the spark-form element. It bubbles up to window, so one listener covers every form on the page. Use event.detail.formId or event.target to tell forms apart. Every event name starts with sparklayer:, so it can't clash with your theme's or other apps' events.

EventWhen it firesExtra in event.detail
sparklayer:form-loadedThe form appears on the page. Not sent for an entry that's already submitted.None
sparklayer:form-startedThe customer's first answer is saved.None
sparklayer:form-field-answeredA field's answer is saved for the first time. Later changes to the same field don't send it again.fieldPath, fieldLabel, fieldType
sparklayer:form-page-changedThe customer moves to another page of a form with several pages.pageIndex (from 0), pageId, pageTitle, pageCount
sparklayer:form-submittedThe entry is submitted.None

Every event.detail also has:

PropertyWhat it is
formIdThe form's ID, as in the embed code.
formTitleThe form's title.
entryIdThe entry's ID, or null until the customer's first answer is saved.

fieldPath is the field's place in the form, such as contacts.email for a field inside a group. Every item of a repeating group reports the same path.

Events never include the customer's answers, as they're often personal data. Forms don't send events for previews or when you edit an entry in the SparkLayer Dashboard.

Send form events to Google Tag Manager

Add this script to your theme, anywhere on the pages that show a form. It pushes each event to the data layer with an underscored name, such as sparklayer_form_submitted, and the event.detail properties as its parameters:

Theme
<script>
  (function () {
    var events = [
      'sparklayer:form-loaded',
      'sparklayer:form-started',
      'sparklayer:form-field-answered',
      'sparklayer:form-page-changed',
      'sparklayer:form-submitted',
    ];
    window.dataLayer = window.dataLayer || [];
    events.forEach(function (name) {
      window.addEventListener(name, function (event) {
        var data = { event: name.replace(':', '_').replace(/-/g, '_') };
        for (var key in event.detail) data[key] = event.detail[key];
        window.dataLayer.push(data);
      });
    });
  })();
</script>

In Tag Manager, add a Custom Event trigger for each event name and send it to GA4 with a GA4 event tag. To send events to GA4 without Tag Manager, call gtag('event', …) in the listener instead of dataLayer.push.

To find where customers drop off, compare the counts of each step for a form:

  • Opened but didn't start: sparklayer_form_loaded against sparklayer_form_started.
  • Started but didn't submit: sparklayer_form_started against sparklayer_form_submitted.
  • Where they stopped: the last sparklayer_form_field_answered or sparklayer_form_page_changed before they left, by fieldPath or pageIndex.

Form CSS variables (for developers)

Each form variable falls back to the matching global variable when it isn't set.

All form CSS variables
Form variableFalls back toControls
--spark-form-max-widthNoneMaximum form width
--spark-form-button-widthNoneButton width, for example 100%
--spark-form-font-default--spark-font-defaultMain font family
--spark-form-header-font--spark-header-fontHeading font family
--spark-form-button-font-family--spark-button-font-familyButton font family
--spark-form-font-default-size-small--spark-font-default-size-smallBase font size on smaller screens
--spark-form-font-default-size--spark-font-default-sizeBase font size
--spark-form-input-font-size--spark-input-font-sizeInput font size
--spark-form-h1-fontsize--spark-h1-fontsizeH1 size
--spark-form-h2-fontsize--spark-h2-fontsizeH2 size
--spark-form-h3-fontsize--spark-h3-fontsizeH3 size
--spark-form-h4-fontsize--spark-h4-fontsizeH4 size
--spark-form-h5-fontsize--spark-h5-fontsizeH5 size
--spark-form-h6-fontsize--spark-h6-fontsizeH6 size
--spark-form-button-small-font-size--spark-button-small-font-sizeSmall button font size
--spark-form-button-font-size--spark-button-font-sizeDefault button font size
--spark-form-button-large-font-size--spark-button-large-font-sizeLarge button font size
--spark-form-font-weight-default--spark-font-weight-defaultDefault font weight
--spark-form-font-weight-medium--spark-font-weight-mediumMedium font weight
--spark-form-font-weight-heavy--spark-font-weight-heavyHeavy font weight
--spark-form-header-font-weight--spark-header-font-weightHeading font weight
--spark-form-button-font-weight--spark-button-font-weightButton font weight
--spark-form-header-text-transform--spark-header-text-transformHeading text transform
--spark-form-header-letter-spacing--spark-header-letter-spacingHeading letter spacing
--spark-form-button-text-transform--spark-button-text-transformButton text transform
--spark-form-button-text-letter-spacing--spark-button-text-letter-spacingButton letter spacing
--spark-form-border-radius-default--spark-border-radius-defaultDefault border radius
--spark-form-border-radius-button--spark-border-radius-buttonButton border radius
--spark-form-input-padding--spark-input-paddingInput padding
--spark-form-button-padding--spark-button-paddingButton padding
--spark-form-product-card-button-padding--spark-product-card-button-paddingProduct card button padding
--spark-form-lightest-color--spark-lightest-colorForm background and light surfaces
--spark-form-default-body-color--spark-default-body-colorBody text colour
--spark-form-header-color--spark-header-colorHeading colour
--spark-form-primary-color--spark-primary-colorPrimary colour
--spark-form-primary-color-light--spark-primary-color-lightLight primary colour
--spark-form-primary-color-dark--spark-primary-color-darkDark primary colour
--spark-form-secondary-color--spark-secondary-colorSecondary colour
--spark-form-link-color--spark-link-colorLink colour
--spark-form-button-color--spark-button-colorButton brand colour
--spark-form-button-raised-color--spark-button-raised-colorPrimary button text colour
--spark-form-button-raised-background--spark-button-raised-backgroundPrimary button background
--spark-form-button-raised-hover-background--spark-button-raised-hover-backgroundPrimary button hover background
--spark-form-button-raised-border-color--spark-button-raised-border-colorPrimary button border colour
--spark-form-button-disabled-color--spark-button-disabled-colorDisabled button text colour
--spark-form-button-large-color--spark-button-large-colorLarge button colour
--spark-form-input-background--spark-input-backgroundInput background
--spark-form-input-border-color--spark-input-border-colorInput border colour
--spark-form-input-text-color--spark-input-text-colorInput text colour
--spark-form-input-focus-border-color--spark-input-focus-border-colorFocused input border colour
--spark-form-table-header-background-color--spark-table-header-background-colorTable header background
--spark-form-success-color--spark-success-colorSuccess state colour
--spark-form-error-color--spark-error-colorError state colour
--spark-form-warn-color--spark-warn-colorWarning state colour
--spark-form-info-color--spark-info-colorInfo state colour
--spark-form-agent-color--spark-agent-colorAgent state colour
--spark-form-company-users-color--spark-company-users-colorCompany users state colour

FAQs

Was this page helpful?

Last updated