This guide is for developers who want to add an Open in MicrobeTrace button to their own web application.
The embed flow is client-only. Your app opens a MicrobeTrace-owned receiver page in a popup or new tab, sends the dataset with postMessage, and MicrobeTrace stores that payload on the MicrobeTrace origin long enough to open it as a session.
The integration has three parts:
- Your application includes the MicrobeTrace embed SDK.
- Your button calls
MicrobeTraceEmbed.open(...)orMicrobeTraceEmbed.attachButton(...)from a user click. - MicrobeTrace validates the payload, stores it as a one-time handoff, and launches the dataset.
- Your webapp origin must be allowlisted by the MicrobeTrace team.
- Your users must trigger the popup from a real click or tap. Browsers will block background popup attempts.
- Your data must fit within the partner handoff limits.
The current defaults are defined in src/assets/embed/partner-allowlist.json:
- Max files:
10 - Max file size:
20 MB - Max total payload:
50 MB - Handoff lifetime:
15 minutes
Add the SDK:
<script src="https://microbetrace.cdc.gov/MicrobeTrace/assets/embed/microbetrace-embed.js"></script>Add a button:
<button id="open-microbetrace">Open In MicrobeTrace</button>Wire it up:
<script>
const files = [
{
name: 'nodes.csv',
mimeType: 'text/csv',
contents: 'id,seq,group\nA,ACTG,alpha\nB,ACTA,beta\n'
},
{
name: 'links.csv',
mimeType: 'text/csv',
kind: 'link', // optional parameter
contents: 'source,target,distance\nA,B,1\n'
}
];
MicrobeTraceEmbed.attachButton('#open-microbetrace', {
target: 'https://microbetrace.cdc.gov/MicrobeTrace/',
partnerId: 'your-partner-id',
files,
metadata: {
datasetName: 'My dataset',
sourceApp: 'My Web App'
},
onSuccess(result) {
console.log('Stored handoff', result.handoffId);
},
onError(error) {
console.error(error.message);
}
});
</script>You can also call MicrobeTraceEmbed.open(options) directly if you want to control the button wiring yourself.
Use this checklist before handing the integration to your users:
- Confirm your site origin is allowlisted for the correct
partnerId. - Confirm the
targetpoints at the correct MicrobeTrace deployment. - Trigger the embed call from a direct user click or tap.
- Pass conventional file names and headers when possible so auto-detection works cleanly.
- Add explicit
kindoroptions.field1/field2/field3when your data shape is unusual. - Test one successful launch on a real browser before release.
Opens the receiver page, sends the payload, and resolves after MicrobeTrace stores the handoff.
Required fields:
target- The root URL of your MicrobeTrace deployment.
- Example:
https://microbetrace.cdc.gov/MicrobeTrace/
partnerId- The partner identifier assigned in the MicrobeTrace allowlist.
files- One or more file payloads.
Optional fields:
metadata.datasetNamemetadata.sourceApponSuccess(result)onError(error)
Attaches the same behavior to one or more existing buttons or links.
This example assumes the SDK script is already loaded on the page.
function OpenInMicrobeTraceButton({ nodesCsv, linksCsv }) {
const handleClick = async () => {
await window.MicrobeTraceEmbed.open({
target: 'https://microbetrace.cdc.gov/MicrobeTrace/',
partnerId: 'your-partner-id',
files: [
{ name: 'nodes.csv', mimeType: 'text/csv', contents: nodesCsv },
{ name: 'links.csv', mimeType: 'text/csv', contents: linksCsv }
],
metadata: {
datasetName: 'My dataset',
sourceApp: 'My React App'
}
});
};
return <button onClick={handleClick}>Open In MicrobeTrace</button>;
}<template>
<button @click="openInMicrobeTrace">Open In MicrobeTrace</button>
</template>
<script>
export default {
props: {
nodesCsv: { type: String, required: true },
linksCsv: { type: String, required: true }
},
methods: {
async openInMicrobeTrace() {
await window.MicrobeTraceEmbed.open({
target: 'https://microbetrace.cdc.gov/MicrobeTrace/',
partnerId: 'your-partner-id',
files: [
{ name: 'nodes.csv', mimeType: 'text/csv', contents: this.nodesCsv },
{ name: 'links.csv', mimeType: 'text/csv', contents: this.linksCsv }
],
metadata: {
datasetName: 'My dataset',
sourceApp: 'My Vue App'
}
});
}
}
};
</script>If you load the SDK dynamically instead of from a static <script> tag, ensure window.MicrobeTraceEmbed exists before rendering or wiring the button.
Each file uses this shape:
{
name: 'nodes.csv',
kind: 'node', // optional
mimeType: 'text/csv',
contents: 'id,seq\nA,ACTG\n',
options: {
extension: 'csv',
field1: 'id',
field2: 'seq',
field3: 'distance'
}
}Fields:
name- Required.
kind- Optional.
- Allowed explicit values:
node,link,matrix,fasta,newick,auspice - You may omit it, or set it to
auto, and let MicrobeTrace infer it.
mimeType- Optional but recommended.
contents- Required.
- Allowed content types:
- string
ArrayBufferfor Excel-backed imports- object or JSON string for Auspice payloads
options.extension- Optional override for file extension inference.
options.field1,options.field2,options.field3- Optional overrides for ambiguous column mappings.
If kind is omitted or set to auto, MicrobeTrace will infer the file type.
Current detection rules:
- Auspice
- JSON object with
metaandtree
- JSON object with
- FASTA
- text starting with
> - or FASTA-style extension such as
fa,fas,fasta,fna
- text starting with
- Newick
- text that looks like a Newick tree
- or tree-style extension such as
nwk,newick,tre
- Matrix
- square tabular data where row labels match column labels and cells are numeric
- or matrix-like filenames such as
distance-matrix.csv
- Link list
- headers like
source/target,src/tgt, orfrom/to - or link-like filenames such as
links.csv
- headers like
- Node list
- tabular data with headers like
idorseq - otherwise this is the fallback for remaining tabular files
- tabular data with headers like
If your dataset uses unusual column names, pass explicit kind or explicit field1/field2/field3.
For node and link files, MicrobeTrace also infers column mappings:
- Node defaults:
field1->idfield2->seqwhen present
- Link defaults:
field1->sourcefield2->targetfield3->distancewhen present
Override them when your headers do not follow the usual names:
{
name: 'pairs.csv',
kind: 'link',
mimeType: 'text/csv',
contents: 'person_a,person_b,weight\nA,B,2\n',
options: {
field1: 'person_a',
field2: 'person_b',
field3: 'weight'
}
}MicrobeTrace currently supports these import families through the embed handoff:
- Node list
- Link or edge list
- Distance matrix
- FASTA
- Newick
- Auspice JSON
The partner handoff does not allow:
- Full MicrobeTrace session objects
- HTML, SVG, or script-like payloads
- Zip files
- Arbitrary untyped binary blobs
The embed flow is intentionally restricted:
- The receiver only accepts messages from allowlisted partner origins.
- The handoff uses a one-time nonce and a one-time handoff id.
- Payloads are schema-validated and size-limited.
- Handoffs are stored in a separate browser-storage namespace on the MicrobeTrace origin.
- Handoffs are deleted after read or on error.
This means partner apps cannot write directly into MicrobeTrace browser storage. They must go through the official receiver flow.
The repository includes working examples:
src/assets/embed/smoke-auto.html- Uses omitted
kindand auto-detection.
- Uses omitted
tmp/embed-smoke/index.html- Uses explicit
nodeandlinkkinds.
- Uses explicit
The checked-in local allowlist currently includes:
http://localhost:4200http://127.0.0.1:4200http://localhost:4300http://127.0.0.1:4300
Common failures:
The partner handoff window was blocked by the browser.- Ensure the SDK is called from a direct user gesture.
The calling origin is not approved for this partner handoff.- Your origin is not yet allowlisted for the supplied
partnerId.
- Your origin is not yet allowlisted for the supplied
File ... did not declare a kind and MicrobeTrace could not infer one.- Pass an explicit
kind.
- Pass an explicit
Requested field ... was not present in the imported dataset.- Update the mapping overrides to match the actual headers.
To onboard a real partner:
- Assign a
partnerId. - Add the partner origin or origins to
src/assets/embed/partner-allowlist.json. - Confirm the correct MicrobeTrace deployment URL for
target. - Share this guide and a partner-specific example payload.
For unusual data shapes, prefer explicit metadata over relying on inference.