Retrieving custom metadata fields from the Pendo back end
Hi everyone - I've searched the forum history and this doesn't seem to have been answered before.
I have user flows in my app where we gradually personalise the user experience more and more based on their activity. A simple way to think of this is to categorize them as 'users' or 'developers'. I have created a custom metadata field for this and each time they reach a crucial step I update their persona by calling 'pendo.identify(....)' and adding that.
So far so good...that shows up in the Pendo UI. But I also need to call this back when they start a new session and this is where the problem comes...getSerializedMetadata() is only returning the core metadata fields, not the custom one I added. Looking at the network flows in my browser I don't seem to be getting anyhing back from the server, only a local cache...
Does anyone know (given a valid account and visitor ID) how to grab the rest of the metadata including custom fields from the server?
コメント
I'm interested in an answer to this question as well.
This is not currently available. Pendo states that only agent metadata can be accessed via custom code blocks with pendo.getSerializedMetadata or with html variables:
How to use Agent Metadata as a guide variable
Another request for accessing custom metadata in guides
However, if you're clever... outside of Pendo guides, you can use an API call to your Pendo subscription with the following:
const response = await fetch(`https://app.pendo.io/api/v1/visitor/${pendo.getVisitorId()}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-pendo-integration-key": "{get key from pendo admin} "
}
});
In your guide code... DON'T DO THIS!
This is exposing your api key in your guide code, meaning any of your visitors could right-click and inspect and see it, giving them access to read and potentially write to your Pendo customer data.
What I could suggest instead is, set up that call in a safe server behind a firewall, which can only be run by certain conditions. Set up the firewalled guide to only return the custom metadata you want (or, if its safe enough, set it up for all custom metadata so it can be used for various use cases). Then call THAT API from your Pendo guide code.
As long as that call is safe as can be (maybe also programatically rotate the API key), you can return any custom metadata to the guide code and do cool stuff with it, such as pre-select their previous response in a poll, or fill in text.... The world is your oyster! But keep in mind, if you fill in variable text, it won't be translated into a language....
Of course, it would be lovely if Pendo could create a safe, firewalled way to do this for us..... :) There are lots of potential security mishaps, as my team has made clear to us.
Code example:
async function fetchCustomMetadata() {
try {
const visitorId = pendo.getVisitorId();
const response = await fetch(`urlfortheapiyourdevcreates/api/user/${visitorId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer somethingherethatyourdevcreates"
}
});
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
const data = await response.json();
if ( data.custom_field) {
fieldValue = data.persona_level;
console.log("Retrieved metadata from custom metadata API:", custom_field);
}
} catch (error) {
console.error("Error fetching data from custom endpoint:", error);
}
}
サインインしてコメントを残してください。