1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to put google analytic on SMF ?

Discussion in 'Content Management' started by Kerunai, May 25, 2007.

  1. #1
    Hi ? how on earth do we put analytics on SMF ?
     
    Kerunai, May 25, 2007 IP
  2. BLaZeR

    BLaZeR Peon

    Messages:
    1,567
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Put your google analytics code in the header or footer.That should do it.
     
    BLaZeR, May 25, 2007 IP
  3. Kerunai

    Kerunai Active Member

    Messages:
    649
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    thanks blaze ...so where do i go from the admin panel ? i just copy n paste, that's all ?
     
    Kerunai, May 25, 2007 IP
  4. EJRaven

    EJRaven Active Member

    Messages:
    253
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Yes, just place the script code atop of below the other script lines on the header.

    If you don't know how to get to your header, I really recommend getting more familiar with your software now, it will save you more time in the long run than asking people where the specific functions are located everytime you need something.
     
    EJRaven, May 25, 2007 IP
  5. SFOD_D223

    SFOD_D223 Peon

    Messages:
    4,512
    Likes Received:
    174
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Using the header or footer template page should be fine.
     
    SFOD_D223, May 25, 2007 IP
  6. ken123

    ken123 Peon

    Messages:
    527
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Which file specifically?
     
    ken123, Sep 10, 2008 IP
  7. ctforumsdotorg

    ctforumsdotorg Banned

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It will be header.php and footer.php
     
    ctforumsdotorg, Sep 10, 2008 IP
  8. geekepic

    geekepic Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Since it normally loads last.
     
    geekepic, Sep 10, 2008 IP
  9. gridsix

    gridsix Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    What if there is no header or footer file? I'm using the latest version of smf and a custom template.
     
    gridsix, Nov 6, 2008 IP
  10. sclek

    sclek Banned

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The footer file is in the folder of the style that you are using.

    eg.
    /styles/default/footer.php
     
    sclek, Nov 7, 2008 IP
  11. Oldiesmann

    Oldiesmann Well-Known Member

    Messages:
    33
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    138
    #11
    That's great if you're using vBulletin, but this topic is about SMF.

    To add it in SMF, open up index.template.php for the theme you're using.

    Look for this code in the template_main_below() function:

    echo '
            </body>
    </html>';
    Code (markup):
    Add the Google Analytics code right between echo ' and </body>.
     
    Oldiesmann, Nov 8, 2008 IP
  12. SFOD_D223

    SFOD_D223 Peon

    Messages:
    4,512
    Likes Received:
    174
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I learned that one the hard way with my own forum. Works like a charm, too.
     
    SFOD_D223, Nov 22, 2008 IP
  13. Mihai

    Mihai Active Member

    Messages:
    567
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #13
    I tried exactly that and get this error:

    The file you tried to save generated the following error:
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in index.template.php on line 468

    This is the code section:

    echo '

    // -----Start of Google Analytics Tracking Code-----
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("***************");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    // -----End of Google Analytics Tracking Code-----

    <div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>
    </body></html>';
    }


    The line with problems is this:

    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));


    Please advise.

    Thanks.
     
    Mihai, Mar 3, 2009 IP
  14. virkalurk

    virkalurk Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Here is how I solved it on SMF 1.1.8

    	echo '
    	<div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>'
    	//Begin Google Analytics
            ?><script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-#######-#");
    pageTracker._trackPageview();
    } catch(err) {}</script><?php echo '
    </body></html>';
    Code (markup):
    I just added a single quote at the end of the first line, closed out PHP, inserted Google Analytics code, reopened php and continued the echo. Make sure to replace the # signs towards the end with your UA string.
     
    virkalurk, Mar 7, 2009 IP
  15. Maverickblogging

    Maverickblogging Greenhorn

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #15
    Thank you for that very helpful advice. I crashed my forum and came here for the correct solution.
     
    Maverickblogging, Apr 5, 2009 IP
  16. TheLasTSamuRai

    TheLasTSamuRai Active Member

    Messages:
    345
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #16


    I have tried this code but i keep getting a parse error ,so i googled it and this is the right code:
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-XXXXXX-X");
    pageTracker._initData();
    pageTracker._trackPageview();
    </script>
    Code (markup):
    Or you can follow this steps so u dont need to edit anything:
    1. Download and install Ad Management mod from http://mods.simplemachines.org/index.php?mod=255
    2. Paste your Google Analytics code into the "Content" box
    3. Set mark on the "Display ads on the bottom of the page"
    4. Save
     
    TheLasTSamuRai, May 7, 2009 IP
  17. zacnin

    zacnin Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    QUOTE: TheLasTSamuRai

    For those of you who are trying to find ways to put google analytics, LastSamuri has the answer. I have tried ever other method/script and crashed the forums numerous times and never was able to have the code catch. His script did the trick! THANK YOU !
     
    zacnin, May 11, 2009 IP
  18. pankajdeoria

    pankajdeoria Banned

    Messages:
    314
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    125
    #18
    Very thankful to you. Got this page in google search engine and justused this. Got success in first attempt.

    :)



     
    pankajdeoria, Jan 4, 2010 IP
  19. tech0925

    tech0925 Greenhorn

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #19



    Sweet, Thnx! I just copied and pasted your html and added my own analytics tracking code and presto.
     
    tech0925, Apr 11, 2010 IP
  20. jobypdmn

    jobypdmn Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    why go through all this trouble just add google analytics mod to Smf and paste your tracking id in admin panel
     
    jobypdmn, Apr 15, 2012 IP