Class CommerceEvent.Builder

  • Enclosing class:
    CommerceEvent

    public static class CommerceEvent.Builder
    extends java.lang.Object
    The Builder class for CommerceEvent. Use this class to create immutable CommerceEvents that can then be logged. There are 3 types of CommerceEvent:
    This class provides a constructor for each type and will verify the contents of the event when build() is called.

    Sample Product event
     
    
      Product product = new Product.Builder("Foo name", "Foo sku", 100.00).quantity(4).build();
      CommerceEvent event = new CommerceEvent.Builder(Product.PURCHASE, product)
              .transactionAttributes(new TransactionAttributes().setId("bar-transaction-id")
              .setRevenue(product.getTotalAmount()))
              .build();
      MParticle.getInstance().logEvent(event);
     
     


    Sample Promotion event
     
    
      Promotion promotion = new Promotion().setCreative("foo-creative").setName("bar campaign");
      CommerceEvent event = new CommerceEvent.Builder(Promotion.VIEW, promotion).build();
      MParticle.getInstance().logEvent(event);
     
     


    Sample Impression event
     
    
       Product product = new Product.Builder("Foo name", "Foo sku", 100.00).quantity(4).build();
       Impression impression = new Impression("foo-list-name", product);
       CommerceEvent event = new CommerceEvent.Builder(impression).build();
       MParticle.getInstance().logEvent(event);
     
     
    • Method Detail

      • screen

        @NonNull
        public CommerceEvent.Builder screen​(@Nullable
                                            java.lang.String screenName)
        Set the screen to associate with this event.
        Parameters:
        screenName - a String name or description of the screen where this event occurred.
        Returns:
        returns this Builder for easy method chaining.
      • currency

        @NonNull
        public CommerceEvent.Builder currency​(@Nullable
                                              java.lang.String currency)
        Set the ISO 4217 currency code to associate with this event.
        Parameters:
        currency - an ISO 4217 String
        Returns:
        returns this Builder for easy method chaining.
      • nonInteraction

        @NonNull
        public CommerceEvent.Builder nonInteraction​(boolean userTriggered)
        Set this CommerceEvent to be measured as non-user-triggered.
        Parameters:
        userTriggered - a Boolean indicating if a user actually performed this event
        Returns:
        returns this Builder for easy method chaining.
      • customAttributes

        @NonNull
        public CommerceEvent.Builder customAttributes​(@Nullable
                                                      java.util.Map<java.lang.String,​java.lang.String> attributes)
        Associate a Map of custom attributes with this event.
        Parameters:
        attributes - the Map of attributes
        Returns:
        returns this Builder for easy method chaining.
      • addCustomFlag

        @NonNull
        public CommerceEvent.Builder addCustomFlag​(@Nullable
                                                   java.lang.String key,
                                                   @Nullable
                                                   java.lang.String value)
        Add a custom flag to this event. Flag keys can have multiple values - if the provided flag key already has an associated value, the value will be appended.
        Parameters:
        key - (required) a flag key, retrieve this from the mParticle docs or solution team for your intended services(s)
        value - (required) a flag value to be send to the service indicated by the flag key
        Returns:
        returns this builder for easy method chaining
      • customFlags

        @NonNull
        public CommerceEvent.Builder customFlags​(@Nullable
                                                 java.util.Map<java.lang.String,​java.util.List<java.lang.String>> customFlags)
        Bulk add custom flags to this event. This will replace any flags previously set via addCustomFlag(String, String)
        Parameters:
        customFlags - (required) a map containing the custom flags for the CommerceEvent
        Returns:
        returns this builder for easy method chaining
      • checkoutStep

        @NonNull
        public CommerceEvent.Builder checkoutStep​(@Nullable
                                                  java.lang.Integer step)
        Set the checkout step of this event. Should be used with the Product.CHECKOUT and Product.CHECKOUT_OPTION actions.
        Parameters:
        step - the Integer step
        Returns:
        returns this Builder for easy method chaining.
      • checkoutOptions

        @NonNull
        public CommerceEvent.Builder checkoutOptions​(@Nullable
                                                     java.lang.String options)
        Set custom options to be associated with the event. Should be used with the Product.CHECKOUT and Product.CHECKOUT_OPTION actions.
        Parameters:
        options - a String describing this checkout step
        Returns:
        returns this Builder for easy method chaining.
      • productListName

        @NonNull
        public CommerceEvent.Builder productListName​(@Nullable
                                                     java.lang.String listName)
        Set the list name with the Products of the CommerceEvent. This value should be used with the Product.DETAIL and Product.CLICK actions.
        Parameters:
        listName - a String name identifying the product list
        Returns:
        returns this Builder for easy method chaining.
      • productListSource

        @NonNull
        public CommerceEvent.Builder productListSource​(@Nullable
                                                       java.lang.String listSource)
        Set the list source name with the Products of the CommerceEvent. This value should be used with the Product.DETAIL and Product.CLICK actions.
        Parameters:
        listSource - a String name identifying the product's list source
        Returns:
        returns this Builder for easy method chaining.
      • impressions

        @NonNull
        public CommerceEvent.Builder impressions​(@NonNull
                                                 java.util.List<Impression> impressions)
        Overwrite the Impressions associated with the CommerceEvent. This should only be used with Impression-based CommerceEvents created with Builder(com.mparticle.commerce.Impression)
        Parameters:
        impressions - the List of products to associate with the CommerceEvent
        Returns:
        returns this Builder for easy method chaining.
      • internalEventName

        @NonNull
        public CommerceEvent.Builder internalEventName​(@Nullable
                                                       java.lang.String eventName)
        Private API used internally by the SDK.
      • shouldUploadEvent

        @NonNull
        public CommerceEvent.Builder shouldUploadEvent​(boolean shouldUploadEvent)
        Manually choose to skip uploading this event to mParticle server and only forward to kits. Note that if this method is not called, the default is to upload to mParticle as well as forward to kits to match the previous behavior.
        Parameters:
        shouldUploadEvent -
        Returns:
        returns this builder for easy method chaining