News:

Wondering if this will always be free?  See why free is better.

Main Menu

Google analytics/code enabler

Started by Nodaz, October 12, 2009, 08:43:22 PM

Previous topic - Next topic

Nodaz

There are several threads here one at SMFhacks and one at the forum for the theme that i use( Outline by Dziner) discussing Google analytics code and how best to implement it in SMF...there really is no cut an dry method.
I tried using a separate .php file with an include as suggested by Google for dynamic pages along with the other suggestions in the other threads.

it has been suggested to use the global footers and headers mod, but i do not believe that code can be edited and or removed with that mod.
All attempts i have made to insert code manually have been met with parsing errors, someone stated they have had success inserting the OLD Google code, but i believe Google is trying to move away from it to the new standard, so that may only be a short term resolution.

What id like to see is a mod similar to the global footers and headers mode that allows any type of code to be inserted globally, BUT it must allow for removal and or editing of code that has already be inserted.

Global insertion of Google analytic code is the main concern.

Admin access only and perhaps the ability to turn on/off specific code without removing it.

Any thoughts?



swtdivalove

Hi, while I am not a modder at all for SMF, I can see one vital thing that could potentially be a huge security risk for the website doing the way that you are suggesting.

I would like to see a mod that adds Google Analytics, then in the ACP enter the unique code that belongs to your site would be a much better approach.

Arantor

The problem with all of these such mods is that they all have to be applied manually on 1.1 anyway since 1.1 mods almost never work directly on custom themes.

It's a bit better on 2.0 but still it's not something entirely reliable. I might see if I can't put a little something together that would help though; it's better to have a mod that simplifies this than to do it entirely by hand, I suppose.

For the record, swtdivalove's approach is exactly where I'd go with this.

Nodaz

thank you for your consideration of this mod. I think it would be a very useful feature, if i read swtdivaloves post correctly , basically all a user would need to do is enter the google track ID and it would be added to the google analytics code built in to the mod?

Arantor


Nodaz

#5
that would be excellent, you mention that this would be an issue with themes?
I ask because i do indeed use a specific them called outline form dziner studios.
how difficult would a manual install be?

Arantor

A manual install would be almost the same as what you'd have to do anyway.

Except that it would come with nice instructions and tell you exactly what to add where.

Nodaz

Quote from: Arantor on October 13, 2009, 06:01:53 PM
A manual install would be almost the same as what you'd have to do anyway.

Except that it would come with nice instructions and tell you exactly what to add where.
awesome sure would appreciate it : )
Any thoughts on a time line, not pushing, just curious.
Thanks

Arantor

Hmmm. Timeline could be interesting.

Do you mean timeline to implement or timeline to have approved by the Customization Team?

If you mean the former, about another 10 minutes. If the latter... as long as it takes.

Nodaz

no problem, appreciate the effort !

Arantor

I've already written this now, I just have to submit it to the mod site :)

Arantor

Because this is a pretty simple mod, the customization team were able to approve this one.

http://custom.simplemachines.org/mods/index.php?mod=2210

Nodaz

#12
awesome, will install later tonight when i get home.
to be sure, in a manual install... i should just substitute the name of my theme in the path indicated in the "select"/ "change/add" instructions for the manual install?
out of curiosity, does this set the code globally ?

Arantor

The mod as it stands will cover the three themes that come with SMF and will add it to the footer of every forum page.

If you need to add it to your own theme, please visit the mod's page, select your version of SMF from the dropdown, and select Parse - this will show you the edits that the mod makes. It's just a case of doing the same edit for your theme.

Nodaz


Nodaz

quick question...should i install the mod and then make just the changes to the index.template.php file in my theme folder?
I only see a settings.english.php file in my themes "languages" folder so i am assuming that it points to the files it needs in files for the default theme( which would already be changed by installing the mod)

Arantor

The changes to Modifications.english.php will need to be done to Themes/yourtheme/languages/Modifications.english.php, or if that doesn't exist, Themes/default/languages/Modifications.english.php. Then the modifications to index.template.php for your theme.

Nodaz

#17
install went fine, and mod seems to function( not sure if it works) on default theme, but but when i changed the code ("select" from the manual install instructions)and edited my theme i get :
Template Parse Error!
There was a problem loading the /Themes/Outline/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.

Parse error: syntax error, unexpected T_STRING in .../Themes/Outline/index.template.php on line 376

367:   </div>
368: </div>
369: </div>';
370:
371: // The following will be used to let the user know that some AJAX process is running
372: echo '
373: <div id="ajax_in_progress" style="display: none;', $context['browser']['is_ie'] && !$context['browser']['is_ie7'] ? 'position: absolute;' : '', '">', $txt['ajax_in_progress'], '</div>';
374: ';
375: global $modSettings;

376: if(!empty($modSettings['googleAnalyticsCode']))

377: echo '<script type="text/javascript">
378: var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
379: document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
380: </script>


is it as simple as
376:    if(!empty($modSettings[\'googleAnalyticsCode\']))
if so why does it work on the default them and not this custom thteme?

Arantor

We do normally ask that mod support should be kept in the mod's own thread.

Delete line 374 here (the '; on its own) to fix the problem. We can't make it magically work on every single theme and had to write it in a best-guess solution that would work on most themes. Unfortunately this one was different.

Nodaz

no problem, step one done...
now this:
Template Parse Error!
There was a problem loading the /Themes/Outline/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.

You may want to try to refresh this page or use the default theme.

Parse error: syntax error, unexpected '/' in .../Themes/Outline/index.template.php on line 389

380: <script type="text/javascript">
381: try {
382: var pageTracker = _gat._getTracker("', $modSettings['googleAnalyticsCode'] . '");
383: pageTracker._trackPageview();
384: } catch(err) {}</script>
385: ';
386:
387: echo '
388: echo '

389: </div></div></div>

390: </body></html>';
391: }
392:
393: // Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..

Advertisement: