From 105b8ad21c5786cf00a42e914e50e6fdc641b3fc Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 11 Oct 2022 12:30:28 +0300 Subject: [PATCH] generalize instructions for affiliate link tracking --- docs/custom-automatic-link-tracking.md | 127 +++++++++++++++++++++++ docs/script-extensions.md | 4 + docs/tracking-cloaked-affiliate-links.md | 105 ------------------- 3 files changed, 131 insertions(+), 105 deletions(-) create mode 100644 docs/custom-automatic-link-tracking.md delete mode 100644 docs/tracking-cloaked-affiliate-links.md diff --git a/docs/custom-automatic-link-tracking.md b/docs/custom-automatic-link-tracking.md new file mode 100644 index 00000000..80c77c31 --- /dev/null +++ b/docs/custom-automatic-link-tracking.md @@ -0,0 +1,127 @@ +--- +title: Automatic link click tracking with URL matching constraints +--- + +import useBaseUrl from '@docusaurus/useBaseUrl'; + +:::note +If you track link clicks, then these count towards your billable monthly pageviews. +::: + +These instructions can be used to start tracking every `` (i.e. link) element on your site with some specified rules. It is very similar to tracking outbound and file download links, but you can choose based on the link URL (`href` attribute), which links are tracked. Below are some example use cases, and the steps you need to take to start automatically tracking link clicks with your own rules. + +## Example use cases + +### Tracking cloaked affiliate links + +Many websites use link cloaking to make their affiliate links cleaner and easier to manage. So rather than linking to `affiliatepartner.com/affiliateid` you would link to a page on your domain name such as `yourdomain.com/go/affiliatepartner`. As these links cannot be tracked with our [outbound-links](outbound-link-click-tracking) extension, you can use these instructions instead. + +### Tracking downloads with pretty URLs + +Say you have many links to `yoursite.com/product/download` that actually redirect to `yoursite.com/123456/Product2.3.exe`. Our [file-downloads](file-downloads-tracking) extension is unable to detect these downloads, but you can still track them using these instructions. + +## 1. Trigger custom events with JavaScript on your site + +First, make sure your tracking setup includes the second line as shown below: + +```html + + +``` +## 2. Add the JavaScript that will be sending the link click events to Plausible + +You need to add the following code to all of the pages where you want to track your links. You should insert the code below into your HTML page `` section, just under the custom event snippet. Here are the changes you will have make in the code: + +- On the line that says `var toBeTracked = '/example/123'` change `/example/123` to what you want to match with. With this example, any link with a URL that contains `/example/123` will be tracked. If simply containing a string value is not enough, see [more flexible URL matching below](#more-flexible-url-matching). +- (Optional) Give your custom event a new name (`var eventName = 'Cloaked Link: Click'`). The default event name is `Cloaked Link: Click`. Feel free to change it. This will be showing up on your Plausible dashboard later. + +```html + +``` + +:::note +To keep things cleaner in your code, you can also copy the code above into a new `.js` file and load it onto every page via ``. If you do this, make sure to copy the code into the `.js` file without the surrounding ` - -``` -## 2. Add the JavaScript that will be sending the link click events to Plausible - -You need to add the code below to all of the pages where you want to track cloaked affiliate link clicks. Make sure to change the script in the line that says `var urlStringToMatch = '/go/'`. Replace `/go/` with whatever is the name of the subfolder that you use to cloak your links. - -You should insert the code below on your HTML page. The script will work nicely in both `` and `` sections. - -```html - -``` -:::note -To keep things cleaner in your code, you can also copy the code above into a new `.js` file and load it onto every page via ``. If you do this, make sure to copy the code into the `.js` file without the surrounding `