Page 1 of 3 123 LastLast
Results 1 to 10 of 23
  1. #1
    Join Date
    Dec 2007
    Location
    Belfast, N.Ireland
    Posts
    96
    Plugin Contributions
    0

    Idea or Suggestion How I Added Google Analytics Tracking Code instead of using a plugin

    How I put the Google Analytics in my ZenCart without A plugin


    The Short Answer

    Get your Google Analytics Code, open this file on your Zen Cart site:
    \includes\templates\MY_Custom_Template\common\tpl_main_page.php

    Scroll to the bottom of the file and just before the final line that is:
    </body>

    Paste in your code from google. Save the file, upload to your live site and that's it.


    The Longer Answer

    I wanted to add the Google Analytics code (GA code) direct to my site and not to use a plugin for my own reasons. But when I got the tracking code from Google, their instructions were to:

    Quote Originally Posted by Google
    2. Paste this code on your site
    Copy the following code, then paste it onto every page you want to track immediately before the closing </head> tag.
    So, I did the sensible thing and created a new google-analytics.js file, and uploaded it to:
    \includes\templates\MY_Custom_Template\jscript\

    Then I couldn't figure out why it wasn't working.

    I searched about on here, and found that some other had the same issue, and suggested adding it before the </body> tag instead. I was a bit concerned, because the post I read were from a while ago, and things change online so quickly.

    But, I had a go at the method I mentioned above (see my short answer), and the new Real-Time beta reporting on GA showed results immediately :) So, all I know that this method works today 18 June 2012 on Zen Cart v 1.5.0

    I wrote this to hopefully save others having to search through tons of posts in mixed threads to find the answer to this problem.

    Should you want a Plugin instead, you could try this one: http://www.zen-cart.com/downloads.php?do=file&id=272
    (I am not connected with this)

    If you want a bit more help with the whole process of setting up a GA account, getting the code and integrating it, one of the contributors on here wrote an article on this: http://pro-webs.net/tutorials/settin...racking-basic/


    I don't know if the way that I have outlined here is the 'proper' or 'recommended' way of doing this, but it appears to work.

    I hope this helps to save some some time for some people.

    Paul

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,004
    Plugin Contributions
    25

    Default Re: How To: Add Google Analytics Tracking Code Directly To Zen Cart Code

    So, I did the sensible thing and created a new google-analytics.js file, and uploaded it to:
    \includes\templates\MY_Custom_Template\jscript\

    Then I couldn't figure out why it wasn't working.
    If you named the file like that, it would not work in any case. You need to start filenames in /jscript/ folders with jscript_, so your file could be like jscript_google-analytics.js.

  3. #3
    Join Date
    Dec 2007
    Location
    Belfast, N.Ireland
    Posts
    96
    Plugin Contributions
    0

    Default Re: How To: Add Google Analytics Tracking Code Directly To Zen Cart Code

    Quote Originally Posted by gjh42 View Post
    If you named the file like that, it would not work in any case. You need to start filenames in /jscript/ folders with jscript_, so your file could be like jscript_google-analytics.js.
    Sorry, yes you are quite right - my bad.
    I was more concerned about writing the post, and by the time I had written it, I had done it the other way on Zen Cart and deleted the .js file.

    Thanks for clearing up any confusion.

    Paul

  4. #4
    Join Date
    Oct 2012
    Posts
    1
    Plugin Contributions
    0

    Default Re: How To: Add Google Analytics Tracking Code Directly To Zen Cart Code

    Hi ardhill, may be a silly question but when you created the jscript_google-analytics.js file, did you remove the <script></script> tags? I just tried it and it seems to work fine. FWIW, I used jscript_ga.js

  5. #5
    Join Date
    Dec 2007
    Location
    Belfast, N.Ireland
    Posts
    96
    Plugin Contributions
    0

    Default Re: How To: Add Google Analytics Tracking Code Directly To Zen Cart Code

    Quote Originally Posted by JaspalX View Post
    Hi ardhill, may be a silly question but when you created the jscript_google-analytics.js file, did you remove the <script></script> tags? I just tried it and it seems to work fine. FWIW, I used jscript_ga.js
    Yes, you are correct.

    These .js files are loaded and run as Javascript by Zen Cart, so you don't need to add the <script></script> tags.

    In fact the ZenCart wiki states:

    Quote Originally Posted by ZenCart wiki
    NOTE: jscript_*.js files must not contain any <script...> .... </script> tags. They should contain ONLY the contents that are to go "between" those tags.
    http://www.zen-cart.com/wiki/index.p...verride_How-To
    Last edited by ardhill; 4 Oct 2012 at 09:04 AM. Reason: Added wiki url

  6. #6
    Join Date
    Oct 2012
    Posts
    3
    Plugin Contributions
    0

    Default Re: How To: Add Google Analytics Tracking Code Directly To Zen Cart Code

    Hi there,

    I'm trying to find a way to add Google -remarketing code to my pages - this seemed like a simple way to "hardwire" it into the page code - I tried, but it simply doesn't show up...

    I'm a little lost - any help would be most appreciated....

    Thanks

  7. #7
    Join Date
    Dec 2007
    Location
    Belfast, N.Ireland
    Posts
    96
    Plugin Contributions
    0

    Default Re: How To: Add Google Analytics Tracking Code Directly To Zen Cart Code

    Quote Originally Posted by stickleback View Post
    I'm trying to find a way to add Google -remarketing code to my pages
    Personally, I had to google - "Google remarketing code" to see what you were talking about

    Sorry, but right now I personally just don't have time to read it up and play with the code. Maybe you could start a new thread on this as there aren't that may people involved in this thread. Others may be able to help that won't read this thread. There is bound to be other people who have done what you want, or are working on it and read the forums here.

    BTW, do you have a short desription of what Google remarketing is?

    Regards,

    Paul

  8. #8
    Join Date
    Apr 2013
    Location
    eglisau switzerland
    Posts
    540
    Plugin Contributions
    0

    Default Re: How To: Add Google Analytics Tracking Code Directly To Zen Cart Code

    Thanks for this; Google Analytics works now.
    Reports are strange. Google analytics shows one visitor per day & google adwords show 30/40?

  9. #9
    Join Date
    Apr 2012
    Location
    Fossil, OR
    Posts
    35
    Plugin Contributions
    0

    Default Re: How I Added Google Analytics Tracking Code instead of using a plugin

    Quote Originally Posted by ardhill View Post
    How I put the Google Analytics in my ZenCart without A plugin


    The Short Answer

    Get your Google Analytics Code, open this file on your Zen Cart site:
    \includes\templates\MY_Custom_Template\common\tpl_main_page.php

    Scroll to the bottom of the file and just before the final line that is:
    </body>

    Paste in your code from google. Save the file, upload to your live site and that's it.


    Paul
    Thanks Paul. Worked perfectly!
    Christine
    "I believe the most important single thing, beyond discipline and creativity is daring to dare." ~Maya Angelou

  10. #10
    Join Date
    Aug 2011
    Posts
    29
    Plugin Contributions
    0

    Default Re: How I Added Google Analytics Tracking Code instead of using a plugin

    I was previously referencing an external file and I can't figure out where I have the code that's referencing it. It stopped working because Google changed the code. I added the new script to the html_header.php file so it would be right before the </head> tag. But I need to delete the old script reference and I can't figure out where it's coded.

    Here's a snippet of /includes/templates/mytemplate/common/html_header.php


    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','//www.google-analytics.com/analytics.js','ga');
    
      ga('create', 'UA-43155911-1', 'oldsummit.com');
      ga('send', 'pageview');
    
    </script>
    </head>
    But the view source shows up like this:

    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','//www.google-analytics.com/analytics.js','ga');
    
      ga('create', 'UA-43155911-1', 'oldsummit.com');
      ga('send', 'pageview');
    
    </script>
    <script src='/google_analytics_auto.js'></script></head>
    I can't find how the google_analytics_auto.js is being inserted. Searching for it using the Developers Tool Kit, or using BBEdit on a local version of the files comes up empty.

    Any ideas what could be inserting it? The javascript file itself has been deleted so it's not autoloading it and anyways it is in the root directory, not one of the special javascript directories. It has be referenced somewhere and I can't find it. Using v. 1.5

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. v139h Google Analytics Conversion Tracking code install
    By split63 in forum General Questions
    Replies: 7
    Last Post: 17 Dec 2015, 04:09 AM
  2. Where to put google analytics tracking code???
    By cmike in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 23 Apr 2014, 08:05 AM
  3. Replies: 6
    Last Post: 3 Oct 2013, 10:36 PM
  4. Ecommerce Tracking code for Google Analytics
    By Endre in forum General Questions
    Replies: 7
    Last Post: 14 Nov 2012, 03:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR