I'm trying to send stock status events onto Google Analytics to measure how many out of stock items are being viewed compared to in stock products.
Here is the snippet of liquid
<!--Stock Status event Sender -->
{% if product.selected_variant.available == true %}
<script>ga('send', 'event', { eventCategory: 'Stock Status', eventAction: 'In Stock Product View'});</script>
{% else %}
<script>ga('send', 'event', { eventCategory: 'Stock Status', eventAction: 'Out of Stock Product View'});</script>
{% endif %}
<!-- End of Stock Status event Sender -->
All results are returning as 'Out of Stock Product View'
Questions:
Is the above correct?
How to I get it to fire the script again if a user selects another variant on the page? A URL parameter gets added e.g ?variant=40014584709205 - Does this count as new page firing?
Looking at current behaviour in GA - it seems to be recording the first event on product view in a session but not again when user browses another product.