Adding custom data

User email

When you already have your users identified within your app, you might want to add their email automatically attached to the bug report. Bugsee provides API's for setting, getting and clearing the email.

!Objective-C

    // setting email
    [Bugsee setEmail:@"name@example.com"]

    // getting email, nil will be returned if email was never set
    NSString *email = [Bugsee getEmail];

    // clearing email
    [Bugsee clearEmail];

!Swift

    // setting email
    Bugsee.setEmail("name@example.com")

    // getting email, nil will be returned if email was never set
    var email = Bugsee.getEmail()

    // clearing email
    Bugsee.clearEmail()

Session/User Attributes

Besides email, any arbitrary attributes can be attached to the report as well. Issues are searchable by these attributes in the Bugsee dashboard as well.

!Objective-C

    [Bugsee setAttribute:@"name" withValue:@"John Doe"];
    [Bugsee setAttribute:@"age" withValue:@23];
    [Bugsee setAttribute:@"married" withValue:@YES];

!Swift

    Bugsee.setAttribute("name", value: "John Doe")
    Bugsee.setAttribute("age", value: 23)
    Bugsee.setAttribute("married", value: false)

Once set, attributes persist until the application is uninstalled from the device. They can be cleared however using the following API.

!Objective-C

    // Clear a single attribute by name
    [Bugsee clearAttribute:@"name"];

    // .. or clear all of them
    [Bugsee clearAllAttributes];

!Swift

    // Clear a single attribute by name
    Bugsee.clearAttribute("name")

    // .. or clear all of them
    Bugsee.clearAllAttributes()

Custom Traces

Traces may be useful when you want to trace how a specific variable or state changes over time right before the problem happens.

There are two ways available to trace a property, manually setting a value or automatically setting an observer on a property of an object.

!Objective-C

    // Manually set value of @15 to property named "credit_balance"
    // any time it changes
    [Bugsee traceKey:@"credit_balance" withVaue:@15];  

!Swift

    // Manually set value of @15 to property named "credit_balance"
    // any time it changes
    Bugsee.trace(key:"credit_balance", value:15)

Custom Events

Events are identified by a string and can have an optional dictionary of parameters that will be stored and passed along with the report.

!Objective-C

    // Without any additional parameters
    [Bugsee registerEvent:@"payment_processed"];

    // ...or with additional custom parameters
    [Bugsee registerEvent:@"payment_processed"
               withParams:@{
                    @"amount": @125,
                    @"currency": @"USD"
                 }];

!Swift

    // Without any additional parameters
    Bugsee.event("payment_processed")

    // ...our with additional custom parameters
    Bugsee.event("payment_processed",
      params:["amount": 125, "currency": "USD"])

File Attachments

Binary files (attachments) can also be added to the report right before report is being sent. The attachment will be available for download right from the issue viewer. Currently both the amount of attachments and their size is limited. Max of 3 attachments, 1M each.

Your class should implement BugseeDelegate protocol and it must set itself as the delegate for Bugsee.

!Objective-C

-(NSArray<BugseeAttachment *> *)bugseeAttachmentsForReport:(BugseeReport *)report
{
    // Only if it's a blocker and on every crash
    if ((report.severity == BugseeSeverityBlocker) ||
        ([report.type isEqualToString:BugseeReportTypeCrash])) {

        BugseeAttachment * att = [BugseeAttachment attachmentWithName:@"internal app db" filename:@"custom.db" data:[NSData dataWithContentsOfFile:pathToMyFile]];

        // Return array with one attachment
        return @[att];
    }

    return @[];
}

// ..somewhere within the class
[Bugsee sharedInstance].delegate = self;

!Swift

func bugseeAttachments(for report: BugseeReport) -> [BugseeAttachment] {
    // Only if it's a blocker and on every crash
    if (report.severity == BugseeSeverityBlocker ||
        report.type == BugseeReportTypeCrash) {

        if let att = BugseeAttachment(name:"internal app db", filename:"custom.db", data:NSData(contentsOfFile:pathToMyFile)) {
            // Return array with one attachment
            return [att]
        }
    }

    return []
}

// ..somewhere within the class
Bugsee.sharedInstance()?.delegate = self;