目录

Example

Function Call

A custom variable of the Function call type can call a class method of an app and pass relevant key values. For example, the event for buying a product in a shopping app contains only the product name. To report the product inventory in this event, perform the following steps:

  1. Implement the class for obtaining the product inventory. Assume that the shopping app has a common class RoomTypeVariable (create it if it does not exist and inherit CustomVariable) for obtaining the product inventory, and the product inventory is obtained based on the passed product name. Then, you can code your app as follows to implement the -(NSString *)getValue:(NSDictionary<NSString *,NSObject *> *)params method to obtain the product inventory.
     RoomTypeVariable.h
    #import <DTMSDK/DTMSDK.h>
    NS_ASSUME_NONNULL_BEGIN
    @interface RoomTypeVariable : CustomVariable
    @end
     
    RoomTypeVariable.m
    #import "RoomTypeVariable.h" 
    @implementation RoomTypeVariable 
    - (NSString *)getValue:(NSDictionary<NSString *,NSObject *> *)params {
    NSString *value = @""; 
    if (params == nil) { 
    NSLog(@"RoomTypeVariable execute: param null");
    } else {
    if ([params.allKeys containsObject:key]) { 
    NSObject *obj = params[@"goodname"]; 
    value = [obj isKindOfClass:[NSString class]] ? (NSString *) obj : @"UNKNOWN"; 
    }      
    }
    return value;
    }
    @end
  2. Create a custom variable of the Event parameter type, which is used to obtain the name of the bought product.

  3. Create a custom variable of the Function call type, which is used to obtain the product inventory.