Reading:
Installing the script

Installing the script

Liam Houlahan
January 29, 2021

To survey your users inside your Saas application you need to install the Product fit Javascript snippet.

You can find the snippet by navigating to Setup > Install. Here you will see the script to copy into your application.

Identifying users (required)

When installing the Product fit Javascript code you must identify who the user is by passing a unique identifier. This is critical as it ensures you profile the user correctly and ensures that duplicate responses aren’t collected.

The unique identifier must be passed into the attribute “user_id”.

<script>
    window.productFitSettings = {
        user_id: '123456', //Must be unique (required)
        name: "Jane Doe", // Full name (optional)
        email: "customer@example.com", // Email address (optional)
        created_at: 1312182000 // Signup date as a Unix timestamp (optional)
    };
    var resource = document.createElement("script");resource.async = "true";resource.src = "https://script.getproductfit.com/client/1234567890.js";resource.crossorigin = "anonymous";var script = document.getElementsByTagName("script")[0];script.parentNode.insertBefore(resource, script);
</script>

Optionally you can pass additional attributes such as “email” and “name”. Passing the email and name help when viewing the responses from your users.

Advanced usage

Tracking events

If you would like to track events within Product fit you can use the code below.

window.productFit.trackEvent("action",
                    { custom_attribute: "value" } //Add any metadata
                    )

You will need to replace the “action” attribute and you can pass your own custom attributes with the event.

Manually updating users

You can also manually update users within Product fit at any time with any attributes you require. To do this use the code below.


window.productFit.createOrUpdateUser({ email: "user@domain.com",
                                     first_name: "John",
                                     last_name: "Doe",
                                     other_attribute: "value"
                                  })

Replace the values with any attributes you need to update.

Backdrop mode

In order to make the survey more visible inside your app you can display a backdrop which covers the entire screen. To display a backdrop add the “backdrop” attribute to your script like it is below:

window.productFitSettings = {
  backdrop: true,
  user_id: '123456', //Must be unique (required)
  name: "Jane Doe", // Full name (optional)
  email: "customer@example.com", // Email address (optional)
  created_at: 1312182000 // Signup date as a Unix timestamp (optional)
};

With the backdrop set your survey will be displayed like the image below.

Did you find this article helpful?
0 out of 0 found this helpful
Still have questions? Chat with us

Related Stories