分支io添加自定义数据

时间:2018-10-05 03:55:01

标签: branch.io

生成分支io链接时如何添加自定义数据?

async generateBranchUrl(cb) {
  const userId = this.props.currentUser.objectId;
  const userEmail = this.props.currentUser.email;
  const branchUniversalObject = await branch.createBranchUniversalObject(userId);
  const linkProperties = { feature: 'userReferral', tags: [userId, userEmail]  };

branchUniversalObject.generateShortUrl(linkProperties, {})
  .then((res) => {
    cb(res);
  })
  .catch((err) => {
    Alert.alert('Failed to generate link');
  });

}

1 个答案:

答案 0 :(得分:1)

假设您正在与React Native SDK集成,则将任何自定义数据添加到contentMetadata下的branchUniversalObject中,如下所示:

let branchUniversalObject = await branch.createBranchUniversalObject('canonicalIdentifier', {
  locallyIndex: true,
  title: 'Cool Content!',
  contentDescription: 'Cool Content Description'}),
  contentMetadata: {
    ratingAverage: 4.2,
    customMetadata: {
      prop1: 'test',
      prop2: 'abc'
    }
  }
})

要读取自定义数据,只需传递您定义的键即可从params对象中获取数据。