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
- Open your page.
- Right-click on any element and click Inspect or Inspect element, depending on the browser you’re using.
- Right-click on the element’s source code and choose Copy > Copy XPath or Copy > XPath, depending on the browser you’re using.
- 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
- Go to Menu > Tag Manager.
- Navigate to Triggers.
- Click Add a trigger.
- Name the trigger and choose the following type: Click.
- Click Next.
- In Event conditions, choose Fire when conditions are met.
- Choose Click element.
- Paste your XPath.
- Change
css
toxpath
in the last box. - Add more conditions if you want.
- When you’re done, click Add.
- Use this trigger for your tag and see how it works in debug mode.
- Click Publish to make changes on your site.
- All done!