Nevin
Nevin

Reputation: 375

Branch io adding custom data

How do you add custom data when generating branch io links?

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');
  });

}

Upvotes: 0

Views: 871

Answers (1)

Joon Lee
Joon Lee

Reputation: 328

Assuming you are integrating with the React Native SDK, you will add any custom data to your branchUniversalObject under contentMetadata as shown below:

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

To read the custom data, just pass the key you defined to grab the data out of the params object.

Upvotes: 1

Related Questions