Skip to content

Instantly share code, notes, and snippets.

@iamdaniele
Last active August 25, 2017 20:30
Show Gist options
  • Save iamdaniele/c6afbbba9d34c26524a932afa9f4873d to your computer and use it in GitHub Desktop.
Save iamdaniele/c6afbbba9d34c26524a932afa9f4873d to your computer and use it in GitHub Desktop.
Suggested implementation for Cart Abandonment
/* Implement and call when the user adds an item to the cart */
protected void addedItemToCart() {
Carnival.logEvent("Add To Cart");
AttributeMap attributes = new AttributeMap();
attributes.putBoolean("add_to_cart", true);
attributes.putBoolean("checkout_complete", false);
Carnival.setAttributes(attributes, new Carnival.AttributesHandler() {
@Override
public void onSuccess() {
// Success
}
@Override
public void onFailure(Error error) {
// Add your logic to retry in case of error
}
});
}
/* Implement and call when there are no items in the cart */
protected void clearedCart() {
Carnival.removeAttribute("add_to_cart", new Carnival.AttributesHandler() {
@Override
public void onSuccess() {
// Success
}
@Override
public void onFailure(Error error) {
// Add your logic to retry in case of error
}
});
Carnival.removeAttribute("checkout_complete", new Carnival.AttributesHandler() {
@Override
public void onSuccess() {
// Success
}
@Override
public void onFailure(Error error) {
// Add your logic to retry in case of error
}
});
}
/* Implement and call on the Checkout Complete/Order Confirmation screen */
protected void completedCheckout() {
Carnival.logEvent("Checkout complete");
Carnival.removeAttribute("add_to_cart", new Carnival.AttributesHandler() {
@Override
public void onSuccess() {
// Success
}
@Override
public void onFailure(Error error) {
// Add your logic to retry in case of error
}
});
Carnival.removeAttribute("checkout_complete", new Carnival.AttributesHandler() {
@Override
public void onSuccess() {
// Success
}
@Override
public void onFailure(Error error) {
// Add your logic to retry in case of error
}
});
}
/* Implement and call when the user adds an item to the cart */
func addedItemToCart() {
Carnival.logEvent("Add To Cart")
let attributes = CarnivalAttributes()
attributes.setBool(true, forKey: "add_to_cart")
attributes.setBool(false, forKey: "checkout_complete")
Carnival.setAttributes(attributes) { (error) in
if error != nil {
print("\(error!.localizedDescription)")
}
}
}
/* Implement and call when there are no items in the cart */
func clearedCart() {
Carnival.removeAttribute(withKey: "added_items", error: nil)
Carnival.removeAttribute(withKey: "checkout_complete") { (error) in
if error != nil {
print("\(error!.localizedDescription)")
}
}
}
/* Implement and call on the Checkout Complete/Order Confirmation screen */
func completedCheckout() {
Carnival.logEvent("Checkout complete")
Carnival.removeAttribute(withKey: "added_items") { (error) in
if error != nil {
print("\(error!.localizedDescription)")
}
}
Carnival.removeAttribute(withKey: "checkout_complete") { (error) in
if error != nil {
print("\(error!.localizedDescription)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment