How to use XPath in a click trigger

Tag Manager

Needed permissions: owner, manage, edit & publish or edit

XPath (XML Path Language) is a path expression that can point you to any web page element. You can use it to set conditions for a click trigger.

In this article, we’ll show you how to find XPath for any element on your web page and how to set the click trigger.

Find XPath for a page element

  1. Open your page.
  2. Right-click on any element and click Inspect or Inspect element, depending on the browser you’re using.
  3. Right-click on the element’s source code and choose Copy > Copy XPath or Copy > XPath, depending on the browser you’re using.
    XPath in the page source code
  4. Keep the copied code. You’ll need it to set the click trigger. In our example the XPath is //*[@id="et-boc"]/div/div[1]/div/div[1]/div[2]/a.

Set up a click trigger

  1. Go to Menu > Tag Manager.
  2. Navigate to Triggers.
  3. Click Add new trigger.
  4. Name the trigger and choose the following type: Click.
    Click trigger in Piwik PRO
  5. Click Next.
  6. In Event conditions, choose Fire when conditions are met.
  7. Choose Click element.
    Event conditions in a trigger
  8. Paste your XPath.
    Event conditions in a trigger
  9. Change css to xpath in the last box.
    Click trigger with xpath
  10. Add more conditions if you want.
  11. When you’re done, click OK.
  12. Use this trigger for your tag and check how it works in debug mode.
  13. Click Publish to make changes on your site.

Was this article helpful?

Technical support

If you still have some questions, visit our community.
There’s always someone ready to help!

Back to help center