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.
What if there is no header or footer file? I'm using the latest version of smf and a custom template.
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>.
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.
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.
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
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 !
Very thankful to you. Got this page in google search engine and justused this. Got success in first attempt.
why go through all this trouble just add google analytics mod to Smf and paste your tracking id in admin panel