Customizing the Metadata captured by BugHerd
- Last updated on March 4, 2020 at 1:06 AM
The BugHerd sidebar can also be configured to override some of its default behaviour as well as display extra information in any tasks that you pass in from a configuration object called BugHerdConfig
.
When setting up BugHerd for the first time, you probably already know you need to add the following code to your site:
<script
type="text/javascript"
src="https://www.bugherd.com/sidebarv2.js?apikey=YOUR-API-KEY-HERE"
async="true"
>
</script>
The BugHerdConfig
object can be set by adding another script tag that initialises the the BugHerdConfig
variable.
<script>
var BugHerdConfig = {
metadata: {
username: "foobar",
version: "1.0",
foo: "bar",
logged_in: "true"
}
};
</script>
Config options
metadata: object
Adding custom meta data to the “Additional Info” area for tasks created on your site is just a matter of adding an object called metadata
to the BugHerdConfig
object within the initialisation script.
The metadata
object is comprised of simple key/value pairs.
var BugHerdConfig = { // META DATA metadata: { username: "foobar", version: "1.0", foo: "bar", logged_in: "true" }
};
Note: the values are strings. If you want to pass in true
as above, send it as the string "true"
.
You can use this to track all sorts of things, from user data to session data, or in our case the UserId and Rails controller/action. Anything you need to help you better diagnose and fix problems! Anything you add will appear under “additional info” in the task details.
pre-populate requester email
If users are logged in on your site, there is no point having them enter their email address again in your feedback widget. You can pre-set it if known.
var BugHerdConfig = { reporter: { email: "someone@example.com", required: "true" } };
The value for “required” specifies whether you would like to make the email field mandatory or not. If “required” is set to “false” (default) the email address field can be left blank by your site visitors. You need to explicitly set the value for “required” to “true” if you’d like to make the field mandatory.