Widget Javascript API

Campaign Properties

The Viral loops snippet creates an object campaign. It contains a set of useful properties and methods:

The campaign.user

user: {
    firstname: "Efi",
    lastname: "",
    email: "[email protected]"
  }

The campaign.referrer

referrer: {
    firstname: "Dimitris",
    lastname: "",
    email: "[email protected]"
  }

Campaign Methods

Identify Participant

campaign.identify registers the user to the campaign. When the user email is available, run the following:

campaign.identify({
    firstname: "Dimlucas",
    lastname: "",
    email: "[email protected]",
  }, () => {
      console.log("Registration completed");
  });

The firstname, lastname and email are taken from your form. firstname and lastname are optional.

The extraData are other data you want to capture about the participant. These are only visible on a special campaign export that we provide on demand.

❗️

Unfortunately, most CMSs (like Unbounce, Lead Pages, Instapage, Squarespace etc.) don’t allow you to run code after form submission so this solution won’t work there. Most form plugins on WordPress also don't support running code after submission.

GDPR Consent

If you want to capture GDPR consent as well, add the consents property in the user object like this:

campaign.identify({
    firstname: "Dimlucas",
    lastname: "",
    email: "[email protected]",
    consents: {
        "1": true
      }
  }, () => {
      console.log("Registration completed");
  });

The Consent ID can be found in the Settings Page of the app, where the GDPR consents are added.


Track Conversion

📘

Learn more about Conversion Tracking

campaign.track is used to track conversions. When the user makes a conversion, you can track it to Viral Loops, as follows:

campaign.track("conversion", function(err, data) {
  console.log(err, data);
});

Note that the conversion tracking works only for referred participants.

Templates that support conversion:

  • The Milestone Referral
  • The Altruistic Referral

Logout

If you need to clear the user data, run the following:

campaign.logout();