TOPIC:

Adding Google tag manager onclick attribute to Submit button 1 month 1 week ago #262389

  • Topic Author
  • Breezrusr
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 19
  • Thanks: 0
Hi,

I'm trying to add this onclick attribute to the submit button of a form:

onclick="return gtag_report_conversion(' example.com/your-link ')"

I tried 2 different methods but they all create bugs in the form:

METHOD 1: Creating custom Submit button (as indicated in this thread bit.ly/3yCeUS5 )
Bug: The onclick attribute is not being added and the form is not being submitted.
Code:
function ff_SUBMITCUSTOM_action(element, action)
{
switch (action) {
case 'click':
onclick="return gtag_report_conversion(' example.com/your-link ')"
break;
default:;
} // switch
} // ff_SUBMITCUSTOM_action
ff_validate_submit();

METHOD 2: Adding a custom initialization script ( bit.ly/3lQFkMt )
BUG: The form is being submitted but not being validated and nothing is being sent to the mailback email or being received in the admin email
CODE:
function ff_FreeAuditRequest_breezy_EN_init()
{
jQuery('#bfSubmitButton').attr('onclick', "gtag_report_conversion(' example.com/your-link ');" + jQuery('#bfSubmitButton').attr('onclick'));

} // ff_FreeAuditRequest_breezy_EN_init

Of course instead of example.com/your-link i put my link. This is just to show the code example.

Any suggestions on what might be going on?

Thanks.

Please Log in or Create an account to join the conversation.

Last edit: Post by Breezrusr.

Adding Google tag manager onclick attribute to Submit button 1 month 1 week ago #262398

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 957
  • Karma: 2
  • Thanks: 50
Hi,

Go to your forms advanced properties > Scripts > Initialization script, click Custom and click Create code framework. Inside the created function (between the curly brackets { }), add the following:
jQuery('#bfSubmitButton').attr('onclick',  'gtag_report_conversion("example.com/your-link");' + jQuery('#bfSubmitButton').attr('onclick')); 

Let me know the Result!

Regards,
Mirko

Please Log in or Create an account to join the conversation.

Adding Google tag manager onclick attribute to Submit button 1 month 1 week ago #262421

  • Topic Author
  • Breezrusr
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 19
  • Thanks: 0
I tried your suggestion and here are the bugs I encountered:

1. If I leave some required fields empty the "Please fill in the required fields" message is being displayed and when I close the message the form is being submitted without letting me fill the required fields first.

2. The double quotes between the url ("example.com/your-link") get transform into html entities (& quote ; example.com/your-link & quote ; ) but I was able to fix that bug by replacing the double quotes with single and the first single quotes with double quotes like so:

jQuery('#bfSubmitButton').attr('onclick', "gtag_report_conversion('example.com/your-link');" + jQuery('#bfSubmitButton').attr('onclick'));

3. Also if I add the return keyword to insert the exact code google is asking to add, like so:

jQuery('#bfSubmitButton').attr('onclick', "return gtag_report_conversion('example.com/your-link');" + jQuery('#bfSubmitButton').attr('onclick'));

the form is being sent without sending any auto-responder/admin emails nor validating any fields.

Other than that the form works perfectly without the google code added to the onclick attribute.

Any other suggestions?

Thanks.

Please Log in or Create an account to join the conversation.

Last edit: Post by Breezrusr.

Adding Google tag manager onclick attribute to Submit button 1 month 1 week ago #262422

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 957
  • Karma: 2
  • Thanks: 50
Hi,

ok, I will see what I can do with this and back to you as soon as possible.

Regards,
Mirko

Please Log in or Create an account to join the conversation.

Adding Google tag manager onclick attribute to Submit button 1 month 1 week ago #262424

  • Topic Author
  • Breezrusr
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 19
  • Thanks: 0
Ok. Thanks. I need to deliver this asap so your help is greatly appreciated.

Please Log in or Create an account to join the conversation.

Adding Google tag manager onclick attribute to Submit button 1 month 1 week ago #262442

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 957
  • Karma: 2
  • Thanks: 50
Hi,

3. Also if I add the return keyword to insert the exact code google is asking to add, like so:


did you try to send the Form with out RETURN keyword?


Regards,
Mirko

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.052 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!