-3

I am making the website using the theme of a university, while I don't have the ability to use plugins and edit the head.php or function.php doc, which are the main method I can find to use Google Analytics on WordPress. I tried to add the code of Google Analytics to other places on our WordPress website, but it doesn't work. Is there anybody who could help me about this? Thank you very much.

1

4 Answers 4

0

Why can't you install plugins or change theme files? So how do you implement the website?

there are many plugins you can use in wordpress plugin repository.

You can also achieve the goal by editing the functions.php file of your active theme and adding the following code at the end of file.

add_action('wp_head', 'my_google_analytics');
function my_google_analytics() { ?>    
?>
    <script>
        // Paste your Google Analytics tracking code script here.
    </script>
<?php
}
2
  • 1
    Thanks for your answer. The website was provided by the university so that I can only use the default theme and cannot change theme files. Is there any way to add the code directly into the body content of the website?
    – Jiangong
    Aug 23, 2020 at 17:09
  • @Jiangong Do you have access to the default theme code? or can you create a child-theme and upload it to server? Aug 23, 2020 at 17:33
0

You can add Google Analytics snippet in an article through an Custom HTML element in widget category (i tried and it works).

Note: for an optimized tracking it is important that the Google Analytics snippet, in addition to the article pages, is also present on all the other pages of the site.

1
  • Thanks for your answer. But why did it show that "Tag <script> is not allowed" when I tried to add custom HTML code?
    – Jiangong
    Aug 23, 2020 at 21:16
0

Add a footer widget (since it renders on all pages). Choose type "Custom Text/HTML" Enter the following content:

<script>
<!-- YOUR GOOGLE ANALYTICS JAVASCRIPT --!>
</script>
1
  • Thanks for your answer. But it showed that "Target <script> is not allowed" when I tried to add "Custom HTML" widget.
    – Jiangong
    Aug 23, 2020 at 21:25
0

I've readed that "Custom HTML" element doesn't work in your pages. Have you tried put a Custom HTML in Widgets? It could work a bit different.

It's very common to put the Analytics code... Ask to the university tech support. The should have other experiencies about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.