Tracking
Forms
To save client fields straight from the inputs of your own forms (e.g. the e-mail on checkout), see Watch form fields in Client Data.
Connect a form to a campaign
HTML
<script>
// in the initialization snippet, instead of SP.init("WEBSITE_ID");
SP.init("WEBSITE_ID", function () {
SP.connectForm('popup_POPUP_ID', '#newsletter-form');
});
</script>Make sure to replace
WEBSITE_IDandPOPUP_IDwith real data.
connectForm sends a form from your website to a Trustisto Overlay or Bar, as if it was submitted in the campaign itself: the data goes to the campaign’s form (the client is saved with the given consents) and the submit counts as an engagement in the campaign stats.
JavaScript
SP.connectForm(id, selector, getForm, preventDefault, formCallback)id- the campaign,popup_<ID>for an Overlay ortopbar_<ID>for a Barselector- CSS selector of the<form>. The form must already be on the page.getForm- function that receives the form element and returns the data to send. By default it reads the e-mail from the firstinput[type="text"]and sends{ email, marketing: true, consent: true }.preventDefault-true(default) stops the browser from submitting the formformCallback- function called with the sent data after the form is sent
JavaScript
SP.connectForm('popup_123', '#newsletter-form', function (form) {
return {
email: form.querySelector('input[name="email"]').value,
marketing: form.querySelector('input[name="agree"]').checked,
consent: true
};
}, false);The form is sent only when getForm returns an email.