this post was submitted on 11 Jun 2023
7 points (100.0% liked)
Free and Open Source Software
17953 readers
7 users here now
If it's free and open source and it's also software, it can be discussed here. Subcommunity of Technology.
This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
If you’re still looking for a solution, have you thought about using a native JavaScript solution?
It could be as simple as placing a click listener on the body element of each page and then having a list of CSS selector rules. Matches is a JS function that you can pass a CSS selector too, so each click that occurs you can loop through an array of selectors.
Alternatively, that array of selectors could be the elements you attach the listeners to directly.
I’d be happy to help create some examples, if you have any extra context 👍
That would be so amazing! I'd love to just accomplish this without any third-party dependency.
I have the ability to fire javascript on specific pages on my site, so this sounds like it may work!
For the benefit of the wider internet, I'll include the details of my triggers and tags here, but I'm going to DM you and send you the same details. Not sure how inter-instance DMing will work on Lemmy, so this is a fallback.
This is how I have the tags and triggers configured in GTM currently:
Hey @bird@beehaw.org, I'll keep this on the post for now as its generic content at the moment.
There are two ways I'm going to suggest:
#1 Plausible's library
You mentioned using Plausible. did you know that if you include their custom event JS library you can just add class names to existing elements? If you're able to adjust the class names on your site this would be a nice and simple way to do things.
For example:
<button class="single_add_to_cart_button button alt plausible-event-name--Affiliate+Click plausible-event--product=product+name">Buy me</button>
For it to work you need to update your Plausible library to
https://your-domain.com/js/script.tagged-events.js
The main issue here is that you have dynamic content being fed back to Plausible at the same time, which this process wouldn't help with unless you can tell you CMS to drop the name of a page's product into the class list. The example above shows what this would look like.
#2 - Custom JavaScript
The other route is just adding in custom JS. We could create a fun little library to add lots of customisation in, but we can keep this quite simple, by pasting the following code at the bottom of a page's body element.
This code will:
If you want to know more about CSS selectors, W3Schools offers some simple examples to learn from.
You'll notice that this just covers the first of the two examples you gave. For your second example it would be good to have some additional information so that we can refine the click listener. For example, are each of these "link" or "button" elements, such as:
<a href="http://other-domain.com">View on Etsy</a>
If you're happy to DM me an example URL on this site, I can give you a complete example for the second set of click listeners?