Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Google Analytics plugin

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
bsh
Smarty Rookie


Joined: 16 Sep 2009
Posts: 5

PostPosted: Thu Sep 17, 2009 2:30 pm    Post subject: Google Analytics plugin Reply with quote

Code:
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */
 
/**
 * Google Analytics plugin
 * Generate XHTML 1.1 valid Google Analytics code
 * Name:     google_analytics<br>
 * Date:     2009.09.17.<br>
 *
 * Examples:
 * <pre>
 * {google_analytics code=UA-xxxxxx-x}
 * </pre>
 *
 * @author   László Kovács <info@laszlokovacs.com>
 * @license http://www.gnu.org/copyleft/gpl.html GPL
 * @param array $params code parameter required
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_google_analytics($params, &$smarty){
 
    if(empty($params['code'])){
        $smarty->trigger_error("google_analytics: missing parameter");
        return;
    }
 
   $return = '
      <script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>
      <script type="text/javascript">
      // <![CDATA[
      try{
      var pageTracker = _gat._getTracker("'.$params['code'].'");
      pageTracker._trackPageview();
      } catch(err) {}
      // ]]>
      </script>';
   
   return $return;
}
 
?>
Back to top
View user's profile Send private message
mifune
Smarty n00b


Joined: 16 Dec 2009
Posts: 2

PostPosted: Wed Jan 20, 2010 10:52 am    Post subject: Reply with quote

hey, ... can someone give me a hand with this. i'm new to smarty and have not yet installed a plugin.

i guess, i have to create a file with the above code in the plugin folder.
but what would be the name of the file? function.google_analytics.php???

then i insert the code {google_analytics code=UA-xxxxxx-x} into my template.

thanks
Back to top
View user's profile Send private message
bsh
Smarty Rookie


Joined: 16 Sep 2009
Posts: 5

PostPosted: Wed Jan 20, 2010 11:41 am    Post subject: answer Reply with quote

@mifune: yes
Back to top
View user's profile Send private message
newjav
Smarty n00b


Joined: 21 Jan 2010
Posts: 3

PostPosted: Thu Jan 21, 2010 7:15 am    Post subject: Reply with quote

Thank You Very Much
Back to top
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Tue Jan 26, 2010 5:56 pm    Post subject: Different way of implementing this Reply with quote

Here is another way to control all kinds of javascript services:

You can see the full source code at:
http://smarty-framework.googlecode.com/svn/trunk/library/plugins/function.advertise.php

Usage examples are similar to:
Code:
{advertise type='infolinks'}
{advertise type='analytics'}


Thank you.
Back to top
View user's profile Send private message Visit poster's website
asmar
Smarty n00b


Joined: 26 Oct 2008
Posts: 4

PostPosted: Fri Jan 06, 2017 8:31 pm    Post subject: Re: Different way of implementing this Reply with quote

The link you posted doesn't work.

bimal wrote:
Here is another way to control all kinds of javascript services:

You can see the full source code at:
http://smarty-framework.googlecode.com/svn/trunk/library/plugins/function.advertise.php

Usage examples are similar to:
Code:
{advertise type='infolinks'}
{advertise type='analytics'}


Thank you.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 927

PostPosted: Sun Jan 08, 2017 8:20 pm    Post subject: Reply with quote

Do check the post date. g.code repo was shut down several years ago.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP