Event tracking gets set regardless
terryupton opened this issue · 1 comments
Following on from Slack conversation. It seems the event tracking gets set regardless on where it is used. Really struggling with this. Whenever I add {% do myAnalytics.sendEvent() %}
- even on an onclick onclick="{% set myAnalytics = eventAnalytics('Call to Action Footer16', contactInformation.email, url(craft.request.path), 'Footer') %} {% do myAnalytics.sendEvent() %}
it seems to add an event upon pageload. Not sure if a bug or my implementation.
@terryupton yeah the problem you're having is that Twig knows nothing about JavaScript. So when you put that code inside of the JavaScript, it's going to get executed no matter what.
When your page is rendered, the Twig template is compiled to PHP (if it wasn't already), and the code to send the event gets executed. Then the page is sent to the browser, and the onclick
handler will be just empty text actually.