Reputation: 1
I am trying to create a Google Analytics event from Google Tag Manager when a user focuses on a form field. I am not able to get the event to show up in my Google Analytics account and am unsure what the cause is, I have reviewed each step and all of the code and GTM setup seem to be correct.
My Tag Manager account is working with many other tags already.
Here is the form code:
<div class="fancybox_form">
<form action="http://cl.exct.net/subscribe.aspx?lid=7135602" method="post" id="subscribe">
<p style="margin: 5px; padding: 0;">* Required fields</p>
<div class="row">
<p class="column large-8 small-16"><label for="">First Name</label><br>
<input class="textfield" type="text" name="First Name" required=""></p>
<p class="column large-8 small-16"><label for="">Last Name</label><br>
<input class="textfield" type="text" name="Last Name" required=""></p>
</div>
<div class="row">
<p class="column large-16 small-16"><label for="">Email Address *</label><br>
<input class="textfield" type="email" name="Email Address" required=""></p>
</div>
<div style="display: none;"><input class="textfield" type="text" name="Subscription Source" required="" value="WIN"></div>
<div class="row">
<p class="submit_container"><input class="button" type="submit"></p>
<p class="column large-16 small-16">We will never give away your information to third parties. See our <a href="http://www.renown.org/disclaimer" target="_parent">privacy policy</a></p>
<p><input type="hidden" name="MID" value="207548"><br>
<input type="hidden" name="thx" value="http://r-bestmedicine.org"><br>
<input type="hidden" name="err" value="http://r-bestmedicine.org/wp-content/themes/rhealthnews/subscribe.php"></p>
</div>
</form>
</div>
Here is the code I have in a Custom HTML tag that is fired on all pages
firing rule -
{{url}} matches RegEx .*
tag code -
<script type="text/javascript">
$(document).ready(function(){
$('form#subscribe :input:first').focusin(function(){
dataLayer.push({'event':'formFieldFocus'});
});
});
</script>
Here is the Classic Google Analytics Tag to push the event from the DataLayer into Google Analytics
firing rule -
{{event}} equals formFieldFocus
Tag -
Tag Type - Classic Google Analtyics
Web Property ID - account ID in a Macro
Track Type - Event
Category - formFieldFocus
Action - {{url}}
Label - {{referrer}}
Any help would be appreciated
Upvotes: 0
Views: 2807
Reputation: 9603
Your form, hosted in an iframe, isn't loading jQuery. Add your jQuery library, and it should work.
Here is a js fiddle.
<script type='text/javascript' src='http://bestmedicinenews.org/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
Upvotes: 1