XF 2.0 Execute function before <xf:submitrow> - integrating Conversions for Google Analytics when thread is posted

Xiomera

Member
Hi there,
I am trying to trigger a code snippet when clicking on the submitrow button (template: forum_post_thread - the post thread button when you are in advanced thread creating view).

It works basically, but at first it fired when the page is loaded like here.
HTML:
<xf:submitrow id="postThreadButton" name="postThreadButton" class="button--cta" submit="{$submitText}" onsubmit="myFunction()" icon="write" sticky="true">
            <xf:html>
                <xf:button class="u-jsOnly" data-xf-click="preview-click" icon="preview" />
                <script >                  
                    ga('send', 'event', 'thread', 'post');
                    </script>  
            </xf:html>
</xf:submitrow>
Then I tried this
https://stackoverflow.com/questions/8053394/how-to-do-something-before-on-submit
and events lick onsubmit/onclick="myFunction" but then nothing happend (no event triggered at all).

I don't use the XF analytics integration (cuz it's the old one - tried it too, doesn't work neither) I use the new analytics.js library like in this guide (snippet in PAGE_CONTAINER).

I also tryed the suggested, perfect solution from google under https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits (2 code snippets on the bottom of this page), where I "disable" the submit feature, when it is clicked I execute the analytics code and then when this is done I triggger the submit (+timeout handling).

Does somebody know how to integrate this correct (fire event when post thread is clicked) in any way or knows how to execute js before the submit does it's load page action in template?

Thank you very much for your time and help!

-Xiomera
 
Yes I'd love to know this too. I'm trying to figure out how to track conversions in AdWords in the payment_initiate_stripe template.
 
Top Bottom