M
M
Max Darkleviathan2017-07-24 17:19:11
PHP
Max Darkleviathan, 2017-07-24 17:19:11

How to add your own onClick="" to the link for each woocommerce product?

Searched all over the internet and couldn't find it.
There is a catalog of goods on Wordpress. You need to bind the function
onClick="ga(....);" for each product in the catalog on clicking.
Moreover, for each product, the values ​​\u200b\u200bshould be different. For example:
1st product -

<a onClick="ga('send', 'event', 'test', 'tovar1');" href="...">

2nd item -
<a onClick="ga('send', 'event', 'test', 'tovar2');" href="...">

3rd item -
<a onClick="ga('send', 'event', 'test', 'tovar3');" href="...">

...........etc.
How to implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WordPress WooCommerce, 2017-07-25
@maxxannik

In general, Google Analytics works well out of the box with https://wordpress.org/plugins/duracelltomi-google-...
Don't forget to add the Google Tag Manager itself.
It already calculates the funnel, channels and a bunch of other analytical gizmos by itself. No extra freezes.
But if you really want to somehow customize a typical funnel and analytics, then in GTM it is possible. You can add triggers. The site does not need to be touched. Everything is done on the GTM side. It is necessary to study the materiel, watch YouTube. There is a whole universe there. But you can do everything or almost everything. Generally without touching the code of the site.

R
Roman Misyura, 2017-07-24
@MindMinimal

ACF | Carbon Fields - as an option for additional fields. Once added and the product can be changed. In the layout of the output of the product - register the output of the field.
On the other hand, what prevents in the analytics to set up, for example, tovar1 - on the ID of a specific product or the like, and already in the layout of the product / catalog to display what you need + the product ID?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question