Skip to content

Instantly share code, notes, and snippets.

@davidlu1001
Created May 13, 2025 10:04
Show Gist options
  • Save davidlu1001/75b229c43d7fa5c7fe9cf4815d3e2e82 to your computer and use it in GitHub Desktop.
Save davidlu1001/75b229c43d7fa5c7fe9cf4815d3e2e82 to your computer and use it in GitHub Desktop.
HowTo - Immuta Tag Hierarchy Extractor

Immuta Tag Hierarchy Extractor

This tool helps you extract all tag hierarchies from an Immuta Governance interface. It identifies and organizes tags into their hierarchical structure and exports them to a CSV file for easy analysis.

Scripts

This toolkit contains two main JavaScript files:

  1. expand-all-sections.js: Expands all collapsible sections in the Immuta interface
  2. immuta-tag-hierarchy-extractor.js: Extracts all tags with their complete hierarchies

How to Use

Prerequisites

  • Access to an Immuta instance
  • Modern web browser (Chrome, Firefox, Edge, or Safari)
  • Basic familiarity with browser developer tools

Step-by-Step Instructions

  1. Log in to your Immuta instance

    Open your web browser and log in to your Immuta platform.

  2. Navigate to the Tags page

    Go to the Governance section where tags are managed.

  3. Open browser developer tools

    • In Chrome/Edge: Press F12 or right-click anywhere on the page and select "Inspect"
    • In Firefox: Press F12 or right-click and select "Inspect Element"
    • In Safari: First enable developer tools in Safari > Preferences > Advanced, then press Command+Option+I
  4. Go to the Console tab

    Click on the "Console" tab in the developer tools panel.

  5. Enable copy functionality (if needed)

    Some environments restrict copying content from web applications. If you encounter issues, run:

    document.designMode = "on";

    After extraction is complete, you can turn it off with:

    document.designMode = "off";
  6. Expand all sections

    To ensure all tags are visible, copy and paste the entire expand-all-sections.js script into the console and press Enter.

    Wait until you see a message like "✅ Successfully expanded X sections" and no more "running again" messages appear.

  7. Extract the tag hierarchies

    Copy and paste the entire immuta-tag-hierarchy-extractor.js script into the console and press Enter.

  8. Check the downloaded CSV file

    The script will automatically download a file named immuta_tags_hierarchical.csv. Check your browser's download location if it doesn't appear.

  9. Analyze the results

    Open the CSV file in Microsoft Excel, Google Sheets, or any spreadsheet application. The file has a special format:

    • The first column contains the leaf node (actual tag)
    • Subsequent columns show the complete hierarchy from root to leaf

Understanding the Output

The CSV file has the following structure:

Leaf Node Level 1 Level 2 Level 3 ...
"Tag1" "Governance" "Category1" "Tag1"
"Tag2" "Governance" "Category1" "Subcategory" "Tag2"
  • Leaf Node column: Contains the actual tag name for easy identification
  • Level columns: Show the complete hierarchy path from the root to the leaf

How the Scripts Work

expand-all-sections.js

This script:

  1. Finds all elements with the chevron-down icon class
  2. Identifies their clickable parent elements
  3. Simulates clicks to expand collapsed sections
  4. Runs recursively to handle newly revealed nested sections

immuta-tag-hierarchy-extractor.js

This script:

  1. Identifies tags using multiple detection strategies:

    • Finds elements with specific classes (e.g., mat-button-wrapper)
    • Locates elements with specific attributes (e.g., data-test-bind="tag-title")
    • Uses XPath patterns to find deeply nested tags
  2. Builds hierarchical paths by:

    • Starting from each identified tag
    • Traversing up the DOM tree to find parent categories
    • Building a complete path from root to leaf
  3. Processes and exports data by:

    • Cleaning and normalizing tag names
    • Removing duplicates and sorting hierarchies
    • Creating a properly formatted CSV with a leaf node column
    • Automatically downloading the file

Troubleshooting

  • No tags found: Make sure you're on the correct Governance/Tags page and try running the expand script again
  • Missing hierarchies: Some deeply nested tags might not be detected; try expanding all sections manually
  • Script errors: Check the console for error messages; they may indicate permission issues or UI changes
  • CSV format issues: If the CSV doesn't open correctly, try importing it with explicit UTF-8 encoding

Limitations

  • The script depends on the current Immuta UI structure; future UI updates may require script modifications
  • Very large tag hierarchies might take time to process
  • The script can only extract tags visible in the UI; hidden or paginated content might be missed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment