• Resolved rkuipers33

    (@rkuipers33)


    Hi,

    I’m using Google Tag Manager (GTM) and am trying to fire events for form submissions.

    I found a example for Google Analytics in the support-pages and adapted it. It seems pretty straightforward, but the event doesn’t show up in the dataLayer.

    Has anyone done this before? Any tips, tricks? Hopefully I’m not the first one trying…

    Thanks,
    Rob

    <script ...
    
    	// Fire off GA event for a failed subscription
    	function yikes_mailchimp_google_analytics_failure( response ) {
    
     		dataLayer.push({
    			'event': 'registrationFailed'
    		});
    
    	}
    
    	// Fire off GA event for a successful subscription
    	function yikes_mailchimp_google_analytics_success( response ) {
    		dataLayer.push({
    			'event': 'registrationComplete'
    		});
    	}</script>
    • This topic was modified 6 years, 3 months ago by rkuipers33.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey Rob,

    I’m not an expert with Google Tags so I am not sure if you have the sufficient JavaScript code in your example to fire off the Google Tags call.

    Can you send me a URL to your website? I will at least be able to tell if this code is being executed.

    Thank you,
    Kevin.

    Thread Starter rkuipers33

    (@rkuipers33)

    Hi,

    Thanks for having a look.

    it’s on https://www.deimplementatiedokter.nl/over-deimplementatiedokter/
    The form is on a popup behind the button ‘STUUR MIJ HET EBOOK’

    It currently only implements the success variant via GTM.

    Regards, Rob

    • This reply was modified 6 years, 3 months ago by rkuipers33.
    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey Rob,

    I’m seeing some strange behavior with the way your form is submitting. And I don’t think the JS calls are being executed. (Although I am seeing a Facebook analytics call go out when a form is submitted).

    Are you using the AJAX or non-AJAX version of the form? If you’re using the AJAX version, can you exclude our plugin’s JS from your caching? I think this might be compounding the problem. (Let me know if you need the specific filename).

    Thank you,
    Kevin.

    Thread Starter rkuipers33

    (@rkuipers33)

    Hi Kevin,

    I’m not using AJAX on this form.

    Settings are:
    Enable AJAX Submission No
    Redirect On Submission No
    Hide Form After Sign Up Yes

    Thanks, Rob

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Can you try enabling AJAX?

    Thread Starter rkuipers33

    (@rkuipers33)

    Hi Kevin,

    You’re right; now I see the registrationComplete event appearing!

    But switching AJAX on, I no longer get to see the green bar with the succes message after submitting. Instead the submit-button stays unchanged and it looks like the form has not yet been submitted.
    I tried with both ‘Hide Form After Sign Up’ Yes and No.
    Is this by design?

    Thanks again, Rob

    • This reply was modified 6 years, 3 months ago by rkuipers33.
    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey Rob,

    Progress!

    Okay, I am not 100% sure what’s happening but it appears like after submitting the form the popup is re-creating itself? If you test it a few times, sometimes you’ll see the error/success message flash onto the screen and then the popup “resets” itself.

    Are you familiar with the behavior I’m talking about? Is this something you have control over?

    Cheers,
    Kevin.

    Thread Starter rkuipers33

    (@rkuipers33)

    Kevin,

    you’re right again: I made a /testpage with just the form on it.
    The problem must be somewhere in the combination of the popups plugin and Easy Forms.
    The yikes-mailchimp-google-analytics hook still works only with AJAX on. If this is by design, it might be good to include in your (BTW excellent) article https://yikesplugins.com/support/knowledge-base/add-google-analytics-event-tracking/

    I think we can close the issue since the problem is obviously not Easy Forms. If I ever figure out the combination with Popups, I’ll let it know here.
    Thanks for all the help Kevin!
    Rob

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hey Rob,

    I can confirm that the Analytics hooks will only work with AJAX. This is not documented in the article (sorry!) and I will add it.

    The behavior of the popup is not related to Easy Forms but it seems like they’ve been integrated in some way. How would the popup know to “refresh itself” after our submit button has been clicked? Theoretically, the popup shouldn’t be aware or care about its contents. This makes me think that there is either custom code to force the popup to refresh after our form has been submitted or there is some setting in the popup that is triggered from button clicks. Let me know if you track down the cause.

    Glad I could help!

    All the best,
    Kevin.

    Thread Starter rkuipers33

    (@rkuipers33)

    For future reference: this code triggers GTM custom-events which in turn contain the unique formid. ??

    function yikes_mailchimp_google_analytics( $form_id ) {
    	?>
    		<script type="text/javascript">
    
    			var form_id = <?php echo $form_id; ?>;
    
    			// Fire off GTM event for a failed subscription
    			function yikes_mailchimp_google_analytics_failure( response ) {
     				dataLayer.push({
    					'event': 'subscriptionFailure',
    					'formid': '<?php echo $form_id; ?>'
    				});
    			}
    
    			// Fire off GTM event for a successful subscription
    			function yikes_mailchimp_google_analytics_success( response ) {
     				dataLayer.push({
    					'event': 'subscriptionSuccess',
    					'formid': '<?php echo $form_id; ?>'
    				});
    			}
    		</script>
    	<?php
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Google Tag Manager’ is closed to new replies.