Tagged: x
-
AuthorPosts
-
September 13, 2016 at 12:28 am #1172538
dwyerdddParticipantI am so confused over where to add following code
<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-75297221-3’, ‘auto’);
ga(‘send’, ‘pageview’);</script>
Some say in functions.php which kills my site and others say in custom javascript of the theme. Can someone please help?
September 13, 2016 at 1:01 am #1172558
dwyerdddParticipantI should ad that I put it into Child theme global javascript without <script> but cannot get it verified. Should I be able to see it on the home page in the source?
September 13, 2016 at 3:17 am #1172679
Paul RModeratorHi,
You can add this in your child theme’s functions.php file.
// Add scripts to wp_footer() function child_theme_footer_script() { ?> <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-75297221-3', 'auto'); ga('send', 'pageview'); </script> <?php } add_action( 'wp_footer', 'child_theme_footer_script' );Hope that helps
September 13, 2016 at 5:46 pm #1173924
dwyerdddParticipantHi Paul
No go. Please refer to attached files.
September 14, 2016 at 12:54 am #1174350
ChristopherModeratorHi there,
You can install Analytics extension from X addons page and insert analytics code there.
Or you can update previous code in child theme’s functions.php to :
function third_party_tracking_code() { ?> <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-75297221-3', 'auto'); ga('send', 'pageview'); </script> <?php } add_action( 'wp_head', 'third_party_tracking_code' );Hope it helps.
September 14, 2016 at 6:05 pm #1175588
dwyerdddParticipantThank you Christopher
September 14, 2016 at 11:05 pm #1176006
FriechModeratorWe’re delighted to assist you with this.
Cheers!
December 13, 2016 at 1:15 am #1290911
ShutsenParticipantHi Themeco,
How come in the snippet below, the first php tag is a closing one (?>) and the second one an opening (<?php).. Where did the first closing one open, and where does the second opening one close?
Thanks for shining some light on this..
function third_party_tracking_code() { ?>
<script>
// Third party tracking code.
</script><?php }
add_action( ‘wp_footer’, ‘third_party_tracking_code’ );
December 13, 2016 at 3:06 am #1291003
ChristianModeratorIt’s best practice not to close PHP. You need to close it when you insert an HTML though and then add an the opening <?php again to continue with the rest of the PHP code. For more details, please see http://php.net/manual/en/language.basic-syntax.phptags.php
Thanks.
December 14, 2016 at 1:36 am #1292369
ShutsenParticipantSuperinteresting. Thanks for clarifying that 🙂
So then I have no clue why analytics doesn’t start tracking.. After double triple checking my php code, my analytics tracking code, correct ftp upload etc, I have no clue why it’s not doing anything..December 14, 2016 at 2:52 am #1292415
LelyModeratorHi There,
To help you better with this, please share your site URL and also the code you have added so we can double check for you. In case you do have caching plugin, please purge cache.
December 18, 2016 at 2:03 am #1297001
ShutsenParticipantThis reply has been marked as private.December 18, 2016 at 2:09 am #1297005
ShutsenParticipantThis reply has been marked as private.December 18, 2016 at 3:20 am #1297040
ChristopherModeratorHi there,
Google analytics was added successfully to your site, please see the attachment.
Hope it helps.
December 19, 2016 at 4:37 am #1297958
ShutsenParticipantIt started analyzing yes! Thank you!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1172538 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
