promotion

Assigns and returns one unique, unused code from the Promotion associated with the email or push/in-app send.

Copy
object promotion()

Requires a template or campaign with an associated Promotion. The promotion’s vars and a unique code will be returned in an object. To simply display a unique promotion code in your sends, you can place this function in your HTML where you need to display the code.

Examples

Insert a Unique Promotion Code

Once you have created your Promotion and uploaded codes, your template can retrieve it using the promotion() function.

To include the promotion code Zephyr:

Use code {promotion().code} to redeem your discount.


Output:

Use code UA5-E2C to redeem your discount.

To include the promotion code and description stored with the promotion Save the returned promotion object into a Zephyr var. Its code and description can then be displayed in the template.

Zephyr:

{promotion = promotion()}
{promotion.vars.description}
Use code {promotion.code} to redeem your discount.

Output:

Get 15% off all purchases over 50$ before December 18th!
Use code UA5-E2C to redeem your discount.

To access the description, offer, and terms and conditions in Zephyr, use the vars field:

{promotion.code}
{promotion.vars.offer}
{promotion.vars.description}
{promotion.vars.terms_and_conditions}

 

Enable the promo code to be copied by tapping the Push notification

When including a promo code in a Push / In-App template, you can enable the subscriber to copy the promo code to their clipboard simply by tapping on the push notification.

To setup this feature:

  1. Include the following key/value pair on the Push / In-App template
    • Key = "promo_code"
    • Value = "{promotion().code}"
  2. Develop the feature on your app using these native classes

iOS Code Examples

Swift:

Copy
import UserNotifications

func userNotificationCenter(_ center: UNUserNotificationCenter, 
                            didReceive response: UNNotificationResponse, 
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    
    let userInfo = response.notification.request.content.userInfo
    
    if let promoCode = userInfo["promo_code"] as? String {
        UIPasteboard.general.string = promoCode
        
        print("Promo code copied to clipboard: \(promoCode)")
    }
    
    completionHandler()
}

Obj-c:

Copy
#import <UserNotifications/UserNotifications.h>

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
       didReceiveNotificationResponse:(UNNotificationResponse *)response 
                withCompletionHandler:(void (^)(void))completionHandler {
    
    NSDictionary *userInfo = response.notification.request.content.userInfo;
    
    NSString *promoCode = userInfo[@"promo_code"];
    
    if (promoCode) {
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        pasteboard.string = promoCode;
        
        NSLog(@"Promo code copied to clipboard: %@", promoCode);
    }
    
    completionHandler();
}

Android Code Examples

Java:

Copy
public class NotificationReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            String promoCode = extras.getString("promo_code");
            
            if (promoCode != null) {
                ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("Promo Code", promoCode);
                clipboard.setPrimaryClip(clip);
                
                Log.d("NotificationReceiver", "Promo code copied to clipboard: " + promoCode);
            }
        }
    }
}

Kotlin:

Copy
class NotificationReceiver : BroadcastReceiver() {
    
    override fun onReceive(context: Context, intent: Intent) {
        val extras: Bundle? = intent.extras
        extras?.getString("promo_code")?.let { promoCode ->
            val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
            val clip = ClipData.newPlainText("Promo Code", promoCode)
            clipboard.setPrimaryClip(clip)
            
            Log.d("NotificationReceiver", "Promo code copied to clipboard: $promoCode")
        }
    }
}