Skip to main content
Glama
PiwikPRO

Piwik PRO MCP Server

Official
by PiwikPRO

triggers_create

Create triggers in Piwik PRO Tag Manager to define when tags fire based on user actions like page views, clicks, or form submissions using JSON attributes and supported trigger types.

Instructions

Create a new trigger in Piwik PRO Tag Manager using JSON attributes.

    Only trigger types listed by `templates_list_triggers()` are supported. Any other type will be refused.

    💡 TIP: Use these tools to discover available trigger templates and their requirements:
    - templates_list_triggers() - List all available trigger templates
    - templates_get_trigger(template_name='page_view') - Get detailed requirements

    This tool uses a simplified interface with 2 parameters: app_id and attributes.
    Use tools_parameters_get("triggers_create") to get the complete JSON schema
    with all available fields, types, and validation rules.

    Args:
        app_id: UUID of the app
        attributes: Dictionary containing trigger attributes for creation. Required fields vary by trigger type:
                   - name: Trigger name (always required)
                   - trigger_type: Trigger type (e.g., 'page_view', 'click', 'form_submission')
                   - conditions: Array of condition objects that define when trigger fires
                   - Additional fields may be required depending on trigger type

    Returns:
        Dictionary containing created trigger information including:
        - data: Created trigger object with id, name, trigger_type, and attributes
        - Trigger conditions and configuration

    Template Discovery:
        Use templates_list_triggers() to see all available trigger templates, or
        templates_get_trigger(template_name='TEMPLATE') for specific requirements.

    Parameter Discovery:
        Use tools_parameters_get("triggers_create") to get the complete JSON schema
        for all available fields. This returns validation rules, field types, and examples.

    Examples:
        # Get available trigger templates first
        templates = templates_list_triggers()

        # Get specific template requirements
        page_view_info = templates_get_trigger(template_name='page_view')

        # Create page view trigger
        attributes = {
            "name": "Homepage Page View",
            "trigger_type": "page_view",
            "conditions": [
                {
                    "condition_id": "9efa6364-8982-45c5-a288-cdabdf7a4001",
                    "variable_id": "page-path-variable-uuid",
                    "condition_type": "equals",
                    "value": "/",
                    "options": {}
                }
            ]
        }

        # Create click trigger
        attributes = {
            "name": "CTA Button Click",
            "trigger_type": "click",
            "conditions": [
                {
                    "condition_id": "8efa6364-8982-45c5-a288-cdabdf7a4002",
                    "variable_id": "click-element-variable-uuid",
                    "condition_type": "equals",
                    "value": "#cta-primary",
                    "options": {"selector_type": "css"}
                }
            ]
        }
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
app_idYes
attributesYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYes

Implementation Reference

  • The MCP tool handler for 'triggers_create', decorated with @mcp.tool, provides documentation, and delegates to the internal create_trigger function after validation.
    @mcp.tool(annotations={"title": "Piwik PRO: Create Trigger"})
    def triggers_create(app_id: str, attributes: dict) -> TagManagerSingleResponse:
        """Create a new trigger in Piwik PRO Tag Manager using JSON attributes.
    
        Only trigger types listed by `templates_list_triggers()` are supported. Any other type will be refused.
    
        💡 TIP: Use these tools to discover available trigger templates and their requirements:
        - templates_list_triggers() - List all available trigger templates
        - templates_get_trigger(template_name='page_view') - Get detailed requirements
    
        This tool uses a simplified interface with 2 parameters: app_id and attributes.
        Use tools_parameters_get("triggers_create") to get the complete JSON schema
        with all available fields, types, and validation rules.
    
        Args:
            app_id: UUID of the app
            attributes: Dictionary containing trigger attributes for creation. Required fields vary by trigger type:
                       - name: Trigger name (always required)
                       - trigger_type: Trigger type (e.g., 'page_view', 'click', 'form_submission')
                       - conditions: Array of condition objects that define when trigger fires
                       - Additional fields may be required depending on trigger type
    
        Returns:
            Dictionary containing created trigger information including:
            - data: Created trigger object with id, name, trigger_type, and attributes
            - Trigger conditions and configuration
    
        Template Discovery:
            Use templates_list_triggers() to see all available trigger templates, or
            templates_get_trigger(template_name='TEMPLATE') for specific requirements.
    
        Parameter Discovery:
            Use tools_parameters_get("triggers_create") to get the complete JSON schema
            for all available fields. This returns validation rules, field types, and examples.
    
        Examples:
            # Get available trigger templates first
            templates = templates_list_triggers()
    
            # Get specific template requirements
            page_view_info = templates_get_trigger(template_name='page_view')
    
            # Create page view trigger
            attributes = {
                "name": "Homepage Page View",
                "trigger_type": "page_view",
                "conditions": [
                    {
                        "condition_id": "9efa6364-8982-45c5-a288-cdabdf7a4001",
                        "variable_id": "page-path-variable-uuid",
                        "condition_type": "equals",
                        "value": "/",
                        "options": {}
                    }
                ]
            }
    
            # Create click trigger
            attributes = {
                "name": "CTA Button Click",
                "trigger_type": "click",
                "conditions": [
                    {
                        "condition_id": "8efa6364-8982-45c5-a288-cdabdf7a4002",
                        "variable_id": "click-element-variable-uuid",
                        "condition_type": "equals",
                        "value": "#cta-primary",
                        "options": {"selector_type": "css"}
                    }
                ]
            }
        """
        return create_trigger(app_id, attributes)
  • Pydantic model TriggerCreateAttributes used for input validation in the triggers_create handler via validate_data_against_model.
    class TriggerCreateAttributes(BaseModel):
        """Attributes for creating triggers with assets-based allowlist enforcement."""
    
        model_config = {"extra": "allow"}
    
        name: str = Field(..., description="Trigger name")
        trigger_type: str = Field(..., description="Trigger type (must match assets)")
        is_active: Optional[bool] = Field(None, description="Whether trigger is active")
    
        @field_validator("trigger_type")
        @classmethod
        def _validate_trigger_type(cls, v: str) -> str:
            allowed = set(list_template_names("tag_manager/triggers"))
            if v not in allowed:
                raise ValueError(f"Unsupported trigger type '{v}'. Use templates_list_triggers() to discover options.")
            return v
  • Helper function that performs the actual Piwik PRO API call to create the trigger after validation.
    def create_trigger(app_id: str, attributes: dict) -> TagManagerSingleResponse:
        try:
            client = create_piwik_client()
    
            # Validate and enforce allowlist through TriggerCreateAttributes
            validated_attrs = validate_data_against_model(attributes, TriggerCreateAttributes)
    
            # Convert to dictionary and filter out None values
            create_kwargs = {k: v for k, v in validated_attrs.model_dump(exclude_none=True).items()}
    
            # Extract required fields
            name = create_kwargs.pop("name")
            trigger_type = create_kwargs.pop("trigger_type")
    
            response = client.tag_manager.create_trigger(
                app_id=app_id, name=name, trigger_type=trigger_type, **create_kwargs
            )
            return TagManagerSingleResponse(**response)
        except BadRequestError as e:
            raise RuntimeError(f"Failed to create trigger: {e.message}")
        except Exception as e:
            raise RuntimeError(f"Failed to create trigger: {str(e)}")
  • Registration point where register_trigger_tools(mcp) is called, which defines and registers the triggers_create tool among others.
    register_tag_tools(mcp)
    register_trigger_tools(mcp)
    register_variable_tools(mcp)
    register_version_tools(mcp)
    register_template_tools(mcp)
  • Tool schema registry mapping 'triggers_create' to TriggerAttributes model for dynamic schema retrieval via tools_parameters_get.
    TOOL_PARAMETER_MODELS: Dict[str, Type[BaseModel]] = {
        "apps_create": NewAppAttributes,
        "apps_update": AppEditableAttributes,
        "audiences_create": NewAudienceAttributes,
        "audiences_update": EditableAudienceAttributes,
        "tracker_settings_app_update": AppTrackerSettings,
        "tracker_settings_global_update": GlobalTrackerSettings,
        "tags_create": TagManagerCreateAttributes,
        "tags_update": TagManagerUpdateAttributes,
        "tags_list": TagFilters,
        "triggers_create": TriggerAttributes,
        "triggers_list": TriggerFilters,
        "variables_create": VariableCreateAttributes,
        "variables_update": VariableUpdateAttributes,
        "variables_list": VariableFilters,
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds valuable behavioral context beyond annotations: it specifies that unsupported trigger types will be refused, mentions the simplified interface with 2 parameters, and provides workflow guidance about template discovery. Since annotations only provide a title, the description carries most of the behavioral disclosure burden effectively, though it doesn't cover rate limits or authentication needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (Args, Returns, Template Discovery, Parameter Discovery, Examples), but it's quite lengthy with extensive examples. While all content is relevant, it could be more front-loaded - the core functionality is clear early, but the examples section is disproportionately large for a description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of creating triggers with type-dependent requirements, the description provides complete context: it explains the creation process, documents parameters thoroughly despite 0% schema coverage, references sibling tools for discovery, provides examples, and mentions that an output schema exists (so return values don't need explanation). This is comprehensive for a tool with nested objects and variable requirements.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by explaining both parameters in detail: app_id is described as a UUID, and attributes is explained as a dictionary with required fields that vary by trigger type. It provides specific examples of required fields (name, trigger_type, conditions) and mentions additional type-dependent fields, adding substantial meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a new trigger') and resource ('in Piwik PRO Tag Manager'), distinguishing it from sibling tools like triggers_get, triggers_list, or triggers_copy. It explicitly mentions using JSON attributes, which differentiates it from simpler creation tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool vs alternatives: it specifies that only trigger types listed by templates_list_triggers() are supported and directs users to use templates_get_trigger() for detailed requirements. It also mentions using tools_parameters_get() for schema details, creating a clear workflow with sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PiwikPRO/mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server