Capture custom data with new bugs
- Last updated on December 15, 2015 at 6:21 AM
Sometimes extra data is required to reproduce a bug someone may have reported using BugHerd. BugHerd allows capturing additional metadata with a bug. What kind of data this might be depends on the website. Examples of such data can include:
- Whether or not the site visitor was logged in
- The User ID of the user who was logged in
- The contents of a shopping cart
- Version number
Meta data
Pass in extra data by setting the BugHerdConfig variable prior to loading the script in your existing BugHerd embed code:
<script type="text/javascript"> var BugHerdConfig = { metadata: { username: "foobar", version: "1.0", foo: "bar", logged_in: "true" } }; (function (d, t) { var bh = d.createElement(t), s = d.getElementsByTagName(t)[0]; bh.type = 'text/javascript'; bh.src = '//www.bugherd.com/sidebarv2.js?apikey=YOUR-API-KEY-HERE'; s.parentNode.insertBefore(bh, s); })(document, 'script'); </script>
In the above example, you would most often substitute the value in quotes with a server side directive. An example of this is:
username: "<%= current_user.name %>",
The custom data will be available in new bug reports under section "additional info", which also contains the default meta data.
Tags
If you'd like to send default tags to the created tasks, you may preset them:
<script type="text/javascript"> var BugHerdConfig = { tags: ['staging', 'pre-alpha'] }; (function (d, t) { var bh = d.createElement(t), s = d.getElementsByTagName(t)[0]; bh.type = 'text/javascript'; bh.src = '//www.bugherd.com/sidebarv2.js?apikey=YOUR-API-KEY-HERE'; s.parentNode.insertBefore(bh, s); })(document, 'script'); </script>
You may also combine the use of tags and metadata. Please consider carefully whether you would like to use tags or metadata for your case. Tags have the advantage that you can filter by them in the admin however note that the pre-populated tags may be modified by members of the project before the bug is submitted. Guests or the public will not be able modify tags, they will always be added to any task they log.
Please feel free to email us on support@bugherd.com if you need any assistance.