• Hello,

    Google wants me to add this to our Contact form 7 button.

    Add the code to a button: This code shows you how to add click tracking functionality to a button using the <button> tag. Replace “https://example.com/your-link&#8221; with the URL for your website.

    <button onclick="return gtag_report_conversion('https://example.com/your-link')">Submit</button>

    What would be the best way to implement this in Contact form 7?

    We only want to track a button click as a “conversion” no other special data or anything else needed.

    Thank you.

    • This topic was modified 3 years, 4 months ago by webmaster1234.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Same problem here

    hi @webmaster1234,
    try with a js event listener:

    <button id="button-submit">BUTTON</button>
    <script>
    document.getElementById('button-submit').addEventListener("click", function() {
      return gtag_report_conversion('https://example.com/your-link');
    });
    </script>
    Thread Starter webmaster1234

    (@webmaster1234)

    @codekraft

    Thanks, Erik,

    Sorry, I’m a newb so we would put this into our contact form 7 form making a new “submit” button with an “ID attribute” named “button-submit”?

    [submit id:button-submit "Submit"]

    Then we input the javascript listener into the theme?

    <script>
    document.getElementById('button-submit').addEventListener("click", function() {
      return gtag_report_conversion('https://example.com/your-link');
    });
    </script>

    For the “your-link” should we just use the same page URL as the form is on? Would that work?

    Thanks for your help.

    the easiest way is to add that code in the form template just below the button in this way:

    [text example-1]
    
    [text example-2]
    
    [submit id:button-submit "Submit"]
    <script>
    document.getElementById('button-submit').addEventListener("click", function() {
      return gtag_report_conversion('https://example.com/your-link');
    });
    </script>

    hope it helps!

    Thread Starter webmaster1234

    (@webmaster1234)

    @codekraft

    Thank you Eric.

    We placed the code inside the CF7 form using the page URL and it worked. We did not receive a “confirmation notice” from CF7 that the form was submitted successfully however the message did still send.

    hi @webmaster1234
    I can’t tell the reason, I would have to check the website or at least the form code…

    Are you sure you didn’t add breakline inside <script>? it’s important, if not a <p> will be added automatically.

    did you receive the response correctly before adding script into the form? try to check the browser console if you see any error message

    A form with scripts needs to look like this (check the screenshot below the page)

    Thread Starter webmaster1234

    (@webmaster1234)

    @codekraft

    Hey Erik. No line break was added the code was directly from here directly into the form.

    It’s ok though, I think the page reload is happening with others also as I have read that used this onclick conversion.

    Yes, we were getting confirmation notice before adding the script however it is not that important to us.

    Thanks again for your help! Appreciate it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding Google Onclick Conversion to CF7 Button’ is closed to new replies.