Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Adding Google Analytics code to all Coppermine pages  (Read 27772 times)

0 Members and 1 Guest are viewing this topic.

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Adding Google Analytics code to all Coppermine pages
« on: November 24, 2005, 10:20:41 pm »

With the master_template plugin, you can modify just one file to add the Google Analytics code to all Coppermine pages, regardless of theme. Without the plugin, you'd have to modify every theme that you want to use.

This is discussed here. Since it is in the context of a discussion, there is more information than necessary, so I paraphrased what donnoman wrote.

Install master template.

Here's the sample code block to use in plugins/master_template/codebase.php:
Code: [Select]
// Add a filter
$thisplugin->add_filter('template_html','change_template_html');

function change_template_html($html)
{
$add_html = <<<EOT
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "NN-NNNNNN-N";
urchinTracker();
</script>
{META}
EOT;
return str_replace('{META}',$add_html,$html);
}

What master template does is that it finds code in a Coppermine source, and replaces it with what you want instead. "Anchor" the javascript code you want to add onto something that is going to exist in all themes, and is in the <head> section.  We could actually choose "<head>" if we wanted to, but Coppermine has a ready made tag for replacement that is already in the <head> section called '{META}';   When making a replacement like this, remember to include the token with the new fragment you are replacing it with so you don't break Coppermine functionality. (ie, add '{META}' back at the tail end of the $add_html string.)

Modify the _uacct to suit.
« Last Edit: November 24, 2005, 10:26:13 pm by TranzNDance »
Logged

TheGamer1701

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 52
    • PartyNation.tv - Always the newest Party Facs from North Germany
Re: Adding Google Analytics code to all Coppermine pages
« Reply #1 on: May 14, 2006, 12:25:02 pm »

Hello,

I wanted to add google analytics to my coppermine.
This worked great (added it to the theme header in template.html), but now the cpg javascript functions aren't working anymore.
e.g. full view or show details.

I already searched the forum.
Any idead how to fix this?

Thanks,
André

CPG-Installation:
URL: http://www.partynation.tv/coppermine/
Version: 1.4.3
Addons/Mods: none
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Logged

arnestad

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Adding Google Analytics code to all Coppermine pages
« Reply #3 on: April 16, 2007, 12:47:33 pm »

Hi.
I  know this thread is getting old, however I'll try to get an answer here first.
I've implemented and installed the plugin like shown above, however so far I can't see any numbers ticking into my analytics charts. Is there any way of controlling that the code works properly? My cpg is located in http://www.fotokunstner.no/kunst

Hope anyone can help me out.
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Adding Google Analytics code to all Coppermine pages
« Reply #4 on: April 16, 2007, 05:13:53 pm »

Could you please post your codebase.php?

The issue is that the code is showing up in your source but it is commented out.
Logged

arnestad

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Adding Google Analytics code to all Coppermine pages
« Reply #5 on: April 16, 2007, 07:34:21 pm »

Thanks for the reply and taking the time to look at my issue, here's the code for codebase.php.

Code: [Select]
<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2006 Coppermine Dev Team
  v1.1 originally written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.10
  $Source$
  $Revision: 3275 $
  $Author: gaugau $
  $Date: 2006-09-03 12:10:47 +0200 (So, 03 Sep 2006) $
**********************************************/

if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');

// Add an install action
$thisplugin->add_action('plugin_install','sample_install');

// Add a configure action
$thisplugin->add_action('plugin_configure','sample_configure');

// Add a filter for the gallery header
$thisplugin->add_filter('gallery_header','sample_header');

$thisplugin->add_filter('plugin_block','sample_block_mgr');


// Sample function to modify gallery header html
function sample_header($html) {
    global 
$thisplugin;
    return 
'<p style="color:red;"><b>This is sample data returned from plugin "'.$thisplugin->name.'".</b></p>'.$html;
}

function 
sample_block_mgr($block) {
    return 
$block;
}


// Install function
// Checks if uid is 'me' and pwd is 'you'; If so, then install the plugin
function sample_install() {

    
// Install
    
if ($_POST['uid']=='me' && $_POST['pwd']=='you') {

        return 
true;

    
// Loop again
    
} else {

        return 
1;
    }
}

// Configure function
// Displays the form
function sample_configure() {
    echo <<< EOT
    <h3>Enter the username ('me') and password ('you') to install</h3>
    <form action="
{$_SERVER['REQUEST_URI']}" method="post">
        uid:<input type="text" name="uid" /><br />
        pwd:<input type="text" name="pwd" /><br />
        <input type="submit" value="Go!" />
    </form>
EOT;
}
?>

Logged

Nibbler

  • Guest
Re: Adding Google Analytics code to all Coppermine pages
« Reply #6 on: April 16, 2007, 09:42:02 pm »

That's the sample plugin.
Logged

arnestad

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Adding Google Analytics code to all Coppermine pages
« Reply #7 on: April 16, 2007, 10:44:58 pm »

I'm terribly sorry, here's the right code

Code: [Select]
<?php
/*************************
  Coppermine Photo Gallery
  ************************
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originaly written by Gregory DEMAR

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  ********************************************
  Coppermine version: 1.4.1
  $Source: /cvsroot/cpg-contrib/master_template/codebase.php,v $
  $Revision: 1.3 $
  $Author: donnoman $
  $Date: 2005/12/08 05:46:49 $
**********************************************/

if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');


// Add a filter
$thisplugin->add_filter('template_html','change_template_html');
// Add an action
$thisplugin->add_action('page_start','change_template');

/*
 * This function allows you to change the template vars that are created after including the theme.php
 */

function change_template()
{
    global 
$template_vanity;
    
    
$template_vanity = <<<EOT
    <div id="vanity">
          <a id="v_php" href="http://www.php.net/" target="_blank"></a>
          <a id="v_mysql" href="http://www.mysql.com/" target="_blank"></a>
          <a id="v_xhtml" href="http://validator.w3.org/check/referer" target="_blank"></a>
          <a id="v_css" href="http://jigsaw.w3.org/css-validator/check/referer" target="_blank"></a>
          <div style="text-align:center">
          <div>

          </div>
          </div>
    </div>
EOT;
}

/*
 * This function changes the themes template.html as it is read into memory.
 * This example adds google analytics code. (Remmed Output if you don't have a valid ID set.
 */

function change_template_html($html
{   
    
$uacct='UA-364514-3';
    
//only change the $uacct above, don't mess with the ones below
    
$add_html='';
    if (
$uacct=='UA-364514-3'$add_html.="\n<!--\n";     
$add_html .= <<<EOT
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "
$uacct";
urchinTracker();
</script>
{META}
EOT;
    if (
$uacct=='UA-364514-3'$add_html.="\n-->\n";
return str_replace('{META}',$add_html,$html);
}

?>

Logged

Nibbler

  • Guest
Re: Adding Google Analytics code to all Coppermine pages
« Reply #8 on: April 16, 2007, 11:25:57 pm »

Do as it says:

//only change the $uacct above, don't mess with the ones below
Logged

wipqozn1

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 60
Re: Adding Google Analytics code to all Coppermine pages
« Reply #9 on: April 30, 2007, 11:21:43 pm »

But why don't add analytics code before </body> tag in template.html file?
Logged

arnestad

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 33
Re: Adding Google Analytics code to all Coppermine pages
« Reply #10 on: April 30, 2007, 11:28:39 pm »

It's all functioning well for me now after Nibbler helped me out, I'm tracking all the traffic coming my way. Thanks for great help!
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Adding Google Analytics code to all Coppermine pages
« Reply #11 on: May 01, 2007, 05:51:37 am »

But why don't add analytics code before </body> tag in template.html file?
That's fine to do if you only use one theme. The use of the master template for this purpose is for multiple themes without having to edit every template.html file.
Logged
Pages: [1]   Go Up
 

Page created in 0.046 seconds with 19 queries.