Plugin Author
Brecht
(@brechtvds)
The shortcode is actually not required for the statistics. As long as the link you have (with any custom code attached you want) goes to the shortlink (the /recommends/ URL) it will be counted towards clicks.
With jQuery it would also be possible to attach a custom event to the earl-link class.
Kind regards,
Brecht
Thanks for the quick reply Brecht, I appreciate that!
With jQuery however, you cannot differentiate between 2 different links on the same page. This is because all eafl links have the same “eafl-link” class but no IDs. This is a problem when I’m writing comparison articles for example and want a different affiliate link for different products.
The only alternative I have now is to remove the eafl-link and replace it with the tag with onclick events which defeats the purpose of using the plugin 🙁
I really like the plugin though! Simple and it works.
I guess I could use a regex to grab all URLs matching a specific pattern and attach the onclick afterwards as another solution?
Plugin Author
Brecht
(@brechtvds)
Can you give me a specific example of the code you’re using for those links (so not through our plugin, but the desired result).
Brecht
Sure. Here is a snippet of the HTML I’d like to have:
This post includes everything you need to know about
<a class="fbtom" href="https://www.foxymonkey.com/recommends/oddsmonkey-vs-pa/" target="_blank" rel="nofollow noopener noreferrer">OddsMonkey</a> and <a class="fbtpa" href="https://www.foxymonkey.com/recommends/profitaccummulator/" target="_blank" rel="nofollow noopener noreferrer">Profit Accumulator</a>
With jQuery I have added this to attach the onclicks:
var fbtoms = document.querySelectorAll('.fbtom');
for (var i=0; i<fbtoms.length; i++) {
fbtoms[i].onclick = function(){fbq('track', 'Purchase', {value: 0.15,currency: 'GBP'})};
}
Same onclick events are attached for the second class (fbtpa).
Plugin Author
Brecht
(@brechtvds)
Ok, thanks for the example. I’ll look into the possibilities!
Brecht
Thanks, Brecht.
I think the easiest thing to do is to add an optional “custom class” text field when trying to create a link.
Cheers,
Michael