ctalyst® – Using your own Rewards Menu

This article will show how to integrate your custom Rewards/Coupon Menu with ctalyst®. This article with provide with some helper functions as well that can be used or modify in order to fit your applications need. In this article the words Coupon and Rewards are used interchangeably

Prerequisites:

Download the ctalyst® Unity Plugin and set it up in your project. For more details on setting up ctalsyt® SDK read Unity 3D – Getting Started with ctalyst.

Creating Rewards Menu:

Initializing Plugin:

Create Empty GameObject and name it ctalystRewardsHandler. Drag and drop the ctalyst_Game_Registration Component from ctalyst.dll file under Assets/DLI/plugins folder onto onto ctalystRewardsHandler GameObject. Fill up the your Publisher Token in “Token” field and Game ID in “Content ID” field in Inspector Window of ctalystRewardsHandler.

Following code will finish the initialization process.


  private ctalyst.ctalystSDK ctalystRewards;
  void Awake()
  {
      ctalystSdk = gameObject.GetComponent<ctalyst.ctalystSDK>();
      
      // Add custom method to execute when Rewards/Coupon Feedback sent Successful
      ctalyst.ctalystSDK.AddCouponFeedBackEventListener(CouponFeedBackEventListener);
  }
  public void CouponFeedBackEventListener()
  {
      // This method will execute if Coupon Feedback is sent successful
      // You can put custom code here ...
  }

Next step is to get all the Coupon Images as Texture2D. Following code will do that.


  private Hashtable couponHashtable;
  void Awake()
  {
      couponHashtable = new Hashtable();
      
      // Get all the Coupons, if any.
      // This method will return the Hashtable (Key, Value pair) list, which has Coupon Texture and filename of the Coupon as Stored on Disk
      couponHashtable = ctalystSdk.GetCouponHashTable();
  }
  public void CouponFeedBackEventListener()
  {
      // This method will execute if Coupon Feedback is sent successful
      // You can put custom code here ...
  }

Coupon Hashtable will be list of “Key, Value pairs”, with Keys representing coupon’s filename as stored on the disk and value represent the Texture2D for the same coupon. You can display the images as you want. There are three action that need to be implemented.

  1. Coupon/Reward Liked – If user liked the coupon.
  2. Coupon/Reward Disliked – If user disliked the coupon.
  3. Coupon/Reward Clicked – If user clicked the coupon that will navigate the user to URL provided by ctalyst®.

Implementing Like a Coupon:

Following code will implement this:


   ctalystSdk.CouponFeedBack(1, coupon_filename);

The above must be called when a user liked a coupon. “1” represents the code that define coupon is liked and “coupon_filename” is the “Key” in couponHastable. Make sure you supply the filename corresponding to coupon itself.

Implementing Dislike a Coupon:

Following code will implement this:


   ctalystSdk.CouponFeedBack(2, coupon_filename);

The above must be called when a user disliked a coupon. “2” represents the code that define coupon is liked and “coupon_filename” is the “Key” in couponHastable. Make sure you supply the filename corresponding to coupon itself.

Implementing Dislike a Coupon:

Following code will implement this:


   ctalystSdk.CouponFeedBack(3, coupon_filename);

The above must be called when a user clicked a coupon. “3” represents the code that define coupon is liked and “coupon_filename” is the “Key” in couponHastable. Make sure you supply the filename corresponding to coupon itself. This will be end up navigating the user to the Coupons Website.