Analytics
5.4K members online now
5.4K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
 
Guide Me
star_border
Reply

Unable to Track Events on My Webpage

[ Edited ]
Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

Hello All,

 

I wanna track who is filling out the form in my website, I.e., http://technoidentity.com/trainings/big-data/

Actually I have installed Classic analytics Code in this website,

 

I am using the below code to track who is filling this form, Will it work or should I use another code.

 

<input id=”85” class=”wpcf7-form-control wpcf7-submit” type=”submit” value=”Talk to us” onClick="ga('send', 'event', { eventCategory: 'Form', eventAction: 'Submit', eventLabel: 'Talk to us', eventValue: 1});">

1 Expert replyverified_user

Unable to Track Events on My Webpage

Top Contributor
# 2
Top Contributor

Hi @Mahesh A

 

Universal analytics event tracking syntax wont work with Classic analytics tracking code snippet

 

Any reason to not upgrade to the current universal analytics tracking code?

If you can upgrade your tracking code snippet.. try the following, needs to be before the closing </head> tag
It will trigger the event when the form is successfully submitted
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
ga('send', 'event', 'form', 'submit', 'Talk to us', 1);
}, false );
</script>

https://contactform7.com/tracking-form-submissions-with-google-analytics/

 

If you need code for classic analytics, it can be found in the dev docs

https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEventTracking

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Unable to Track Events on My Webpage

Follower ✭ ☆ ☆
# 3
Follower ✭ ☆ ☆

Thank you so much Bronwyn,

 

Should I copy this code as the same, or should I change any function name or else according to my webpage?

Unable to Track Events on My Webpage

[ Edited ]
Top Contributor
# 4
Top Contributor

I could not get event tracking to work for the classic ga.js tracking code

 

however if you update your tracking code on site to the current universal analytics.js version

then the following worked to track events when a form is submitted
(code edited due to type)

<script>
document.addEventListener( 'wpcf7submit', function( event ) {
ga('send', 'event', 'form', 'submit', 'Talk to us', 1);
}, false );
</script>

 

If you need further help in getting it to work with the older tracking code, i suggest following up with the plugin creator

https://wordpress.org/support/plugin/contact-form-7

 

 

 

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Unable to Track Events on My Webpage

Follower ✭ ☆ ☆
# 5
Follower ✭ ☆ ☆

Hello Maam,

 

I have tried the above code, But it is not working. Could you please check once.

 

Unable to Track Events on My Webpage

[ Edited ]
Top Contributor
# 6
Top Contributor

Hi :-)

Code should read:

<script>
document.addEventListener( 'wpcf7submit', function( event ) {
ga('send', 'event', 'form', 'submit', 'Talk to us', 1);
}, false );
</script>

 

You need to place it after the analytics tracking code snippet.. 

tracking code snippet should be before the closing </head> tag.

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Unable to Track Events on My Webpage

Follower ✭ ☆ ☆
# 7
Follower ✭ ☆ ☆

Is this fine?

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-85343869-1', 'auto');
ga('send', 'pageview');
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
ga('send', 'event', 'form', 'submit', 'Talk to us', 1);
}, false );
</script>
</script>
</body>
</html>

Marked as Best Answer.
Solution
Accepted by topic author Mahesh A
January

Re: Unable to Track Events on My Webpage

[ Edited ]
Top Contributor
# 8
Top Contributor

remove this current code from the site pages (its incorrect and before the opening <head> tag):

<script>
document.addEventListener( 'wpcf7-mail-sent-ok', function( event ) {
ga('send', 'event', 'form', 'submit', 'Talk to us', 1);
}, false );
</script>

remove-cf7.jpg


Mahesh A wrote:

Is this fine?

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-85343869-1', 'auto');
ga('send', 'pageview');
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
ga('send', 'event', 'form', 'submit', 'Talk to us', 1);
}, false );
</script>
</script>
</body>
</html>


no.. the code should read as:

 

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-85343869-1', 'auto');
ga('send', 'pageview');

</script>
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
ga('send', 'event', 'form', 'submit', 'Talk to us', 1);
}, false );
</script>

</head>

<body class=" etc etc etc

 

 

 

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here