| 1 |
<?php
|
| 2 |
// $Id: omniture.module,v 1.6 2008/10/07 03:03:36 ultimateboy Exp $
|
| 3 |
/*
|
| 4 |
* @file
|
| 5 |
* Drupal Module: Omniture SiteCatalyst Stats
|
| 6 |
* Adds the required Javascript to the bottom of all your Drupal pages
|
| 7 |
* to allow tracking by the Omniture SiteCatalyst statistics package.
|
| 8 |
* Based on the Google Analytics package by Mike Carter
|
| 9 |
*
|
| 10 |
* @author: Greg Knaddison
|
| 11 |
* @co-maintainer: Matthew Tucker
|
| 12 |
*
|
| 13 |
*/
|
| 14 |
|
| 15 |
function omniture_help($path, $arg) {
|
| 16 |
switch ($path) {
|
| 17 |
case 'admin/help#omniture':
|
| 18 |
return t("Settings for Omniture's SiteCatalyst package");
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
| 22 |
function omniture_perm() {
|
| 23 |
return array('administer SiteCatalyst configuration');
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Implementation of hook_menu
|
| 28 |
*/
|
| 29 |
function omniture_menu() {
|
| 30 |
$items = array();
|
| 31 |
|
| 32 |
$items['admin/settings/omniture'] = array(
|
| 33 |
'title' => 'SiteCatalyst',
|
| 34 |
'description' => 'Configure the settings used to integrate Omniture\'s SiteCatalyst.',
|
| 35 |
'page callback' => 'drupal_get_form',
|
| 36 |
'page arguments' => array('omniture_admin_settings'),
|
| 37 |
'access arguments' => array('administer SiteCatalyst configuration'),
|
| 38 |
'type' => MENU_NORMAL_ITEM,
|
| 39 |
);
|
| 40 |
|
| 41 |
return $items;
|
| 42 |
}
|
| 43 |
|
| 44 |
/**
|
| 45 |
* Implementation of hook_footer() to insert Javascript at the end of the page
|
| 46 |
*/
|
| 47 |
function omniture_footer($main = 0) {
|
| 48 |
|
| 49 |
global $user;
|
| 50 |
|
| 51 |
// Check if we should track the currently active user's role
|
| 52 |
$track = 0;
|
| 53 |
foreach ($user->roles as $role) {
|
| 54 |
$role = str_replace(' ', '_', $role);
|
| 55 |
$track += variable_get("omniture_track_{$role}", FALSE);
|
| 56 |
}
|
| 57 |
|
| 58 |
// Don't track page views in the admin sections, or for certain roles
|
| 59 |
if (arg(0) != 'admin' && $track > 0) {
|
| 60 |
|
| 61 |
// Add any custom code snippets if specified
|
| 62 |
$codesnippet = variable_get('omniture_codesnippet', '');
|
| 63 |
|
| 64 |
// Taxonomy specific stuff - only for nodes
|
| 65 |
if ($node = menu_get_object()) {
|
| 66 |
$tax = $node->taxonomy;
|
| 67 |
|
| 68 |
$vocabularies = taxonomy_get_vocabularies();
|
| 69 |
foreach ($vocabularies as $vid => $vocab) {
|
| 70 |
if ($vocab->tags == 0) {
|
| 71 |
if ($variable_name = variable_get("omniture_vocabvidvar_{$vocab->vid}", FALSE)) {
|
| 72 |
$terms_for_omniture = "";
|
| 73 |
foreach ($node->taxonomy as $tid => $taxonomy) {
|
| 74 |
if ($taxonomy->vid == $vid) {
|
| 75 |
if (strlen($terms_for_omniture) > 0) {
|
| 76 |
$terms_for_omniture .= ','. $taxonomy->name;
|
| 77 |
}
|
| 78 |
else {
|
| 79 |
$terms_for_omniture .= $taxonomy->name;
|
| 80 |
}
|
| 81 |
}
|
| 82 |
}
|
| 83 |
if (isset($terms_for_omniture)) {
|
| 84 |
$omniture_vocab_vars[$variable_name] = $terms_for_omniture;
|
| 85 |
}
|
| 86 |
}
|
| 87 |
}
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
// Format and combine variables in the "right" order
|
| 92 |
// Right order is the code file (least likely to be maintained)
|
| 93 |
// Then admin settings with codesnippet first and finally taxonomy->vars
|
| 94 |
$extra_variables_formatted = $codesnippet;
|
| 95 |
|
| 96 |
if (isset($omniture_vocab_vars)) {
|
| 97 |
foreach ($omniture_vocab_vars as $variable => $value) {
|
| 98 |
$extra_variables_formatted .= "\n". $variable .'="'. $value .'";';
|
| 99 |
}
|
| 100 |
}
|
| 101 |
|
| 102 |
$header = "<!-- SiteCatalyst code version: H.13. Copyright 1997-2007 Omniture, Inc. More info available at http://www.omniture.com -->\n";
|
| 103 |
$header .= "<script type=\"text/javascript\" language=\"JavaScript\" src=\"";
|
| 104 |
$header .= check_plain(variable_get("omniture_js_file_location", 'http://www.example.com/js/s_code_remote_h.js'));
|
| 105 |
$header .= "\"></script>\n";
|
| 106 |
$header .= "<script type=\"text/javascript\" language=\"JavaScript\"><!--\n";
|
| 107 |
|
| 108 |
$footer = '/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/'."\n";
|
| 109 |
$footer .= 'var s_code=s.t();if(s_code)document.write(s_code)//--></script>'."\n";
|
| 110 |
$footer .= '<script language="JavaScript" type="text/javascript"><!--'."\n";
|
| 111 |
$footer .= "if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')"."\n";
|
| 112 |
$footer .= '//--></script><noscript><a href="http://www.omniture.com" title="Web Analytics"><img src="';
|
| 113 |
$footer .= check_plain(variable_get("omniture_image_file_location", 'http://examplecom.112.2O7.net/b/ss/examplecom/1/H.13--NS/0')) .'"'."\n";
|
| 114 |
$footer .= 'height="1" width="1" border="0" alt="" /></a></noscript><!--/DO NOT REMOVE/-->'."\n";
|
| 115 |
$footer .= '<!-- End SiteCatalyst code version: H.13. -->'."\n";
|
| 116 |
|
| 117 |
if ($omniture_hooked_vars = module_invoke_all('omniture_variables', $main)) {
|
| 118 |
if (isset($omniture_hooked_vars['header'])) {
|
| 119 |
$header = $omniture_hooked_vars['header'];
|
| 120 |
}
|
| 121 |
if (isset($omniture_hooked_vars['variables'])) {
|
| 122 |
foreach ($omniture_hooked_vars['variables'] as $k => $v) {
|
| 123 |
$extra_variables_formatted .= "$k=\"$v\";\n";
|
| 124 |
}
|
| 125 |
}
|
| 126 |
if (isset($omniture_hooked_vars['footer'])) {
|
| 127 |
$footer = $omniture_hooked_vars['footer'];
|
| 128 |
}
|
| 129 |
}
|
| 130 |
|
| 131 |
$script = $header;
|
| 132 |
$script .= $extra_variables_formatted;
|
| 133 |
$script .= $footer;
|
| 134 |
|
| 135 |
return $script;
|
| 136 |
}
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* Implementation of hook_admin_settings() for configuring the module
|
| 141 |
*/
|
| 142 |
function omniture_admin_settings() {
|
| 143 |
$form['general'] = array(
|
| 144 |
'#type' => 'fieldset',
|
| 145 |
'#title' => t('General Settings'),
|
| 146 |
'#collapsible' => TRUE,
|
| 147 |
'#description' => t('General settings')
|
| 148 |
);
|
| 149 |
|
| 150 |
$form['general']['omniture_js_file_location'] = array(
|
| 151 |
'#type' => 'textfield',
|
| 152 |
'#title' => t("Complete path to SiteCatalyst Javascript file"),
|
| 153 |
'#default_value' => check_plain(variable_get("omniture_js_file_location", 'http://www.example.com/js/s_code_remote_h.js')),
|
| 154 |
);
|
| 155 |
|
| 156 |
$form['general']['omniture_image_file_location'] = array(
|
| 157 |
'#type' => 'textfield',
|
| 158 |
'#title' => t("Complete path to SiteCatalyst Image file"),
|
| 159 |
'#default_value' => check_plain(variable_get("omniture_image_file_location", 'http://examplecom.112.2O7.net/b/ss/examplecom/1/H.13--NS/0')),
|
| 160 |
);
|
| 161 |
|
| 162 |
// Render the role overview.
|
| 163 |
$result = db_query('SELECT * FROM {role} ORDER BY name');
|
| 164 |
|
| 165 |
$form['roles'] = array(
|
| 166 |
'#type' => 'fieldset',
|
| 167 |
'#title' => t('User Role Tracking'),
|
| 168 |
'#collapsible' => TRUE,
|
| 169 |
'#description' => t('Define what user roles should be tracked by SiteCatalyst.')
|
| 170 |
);
|
| 171 |
|
| 172 |
while ($role = db_fetch_object($result)) {
|
| 173 |
// can't use empty spaces in varname
|
| 174 |
$role_varname = $string = str_replace(' ', '_', $role->name);
|
| 175 |
$form['roles']["omniture_track_{$role_varname}"] = array(
|
| 176 |
'#type' => 'checkbox',
|
| 177 |
'#title' => t($role->name),
|
| 178 |
'#default_value' => variable_get("omniture_track_{$role_varname}", FALSE),
|
| 179 |
);
|
| 180 |
}
|
| 181 |
|
| 182 |
$form['vocabs'] = array(
|
| 183 |
'#type' => 'fieldset',
|
| 184 |
'#title' => t('Vocabulary Variables'),
|
| 185 |
'#collapsible' => TRUE,
|
| 186 |
'#description' => t('Define which vocabularies should should be tracked by which SiteCatalyst variables. Only applies to the full node view (e.g. node/1 or the aliased version of a node). Leave blank to disable for a vocabulary. Multiple terms from a "Multiple select" vocabulary will be placed into a comma separated list. Not available for "Free tagging" vocabularies.')
|
| 187 |
);
|
| 188 |
|
| 189 |
// Allow setting a vocabulary into a variable
|
| 190 |
$vocabularies = taxonomy_get_vocabularies();
|
| 191 |
foreach ($vocabularies as $vid => $vocab) {
|
| 192 |
if ($vocab->tags == 0) {
|
| 193 |
$form['vocabs']["omniture_vocabvidvar_{$vocab->vid}"] = array(
|
| 194 |
'#type' => 'textfield',
|
| 195 |
'#title' => t('Variable for %vocab', array('%vocab' => $vocab->name)),
|
| 196 |
'#default_value' => variable_get("omniture_vocabvidvar_{$vocab->vid}", FALSE),
|
| 197 |
);
|
| 198 |
}
|
| 199 |
}
|
| 200 |
|
| 201 |
$form['advanced'] = array(
|
| 202 |
'#type' => 'fieldset',
|
| 203 |
'#title' => t('Advanced'),
|
| 204 |
'#collapsible' => TRUE,
|
| 205 |
'#collapsed' => TRUE,
|
| 206 |
'#description' => t('You can add custom SiteCatalyst code here.')
|
| 207 |
);
|
| 208 |
|
| 209 |
$form['advanced']['omniture_codesnippet'] = array(
|
| 210 |
'#type' => 'textarea',
|
| 211 |
'#title' => t('JavaScript Code'),
|
| 212 |
'#default_value' => variable_get('omniture_codesnippet', ''),
|
| 213 |
'#rows' => 15,
|
| 214 |
'#description' => t('Paste <a href="@snippets">custom code snippets here</a>. These will be added to every page that SiteCatalyst appears on. For help with this feature see the <a href="@blog">cutroni.com blog</a>. <strong>Do not include the <script> tags</strong>, and always end your code with a semicolon (;).', array('@snippets' => 'http://drupal.org/node/39282', '@blog' => 'http://cutroni.com/blog/') )
|
| 215 |
);
|
| 216 |
|
| 217 |
return system_settings_form($form);
|
| 218 |
}
|
| 219 |
|
| 220 |
|
| 221 |
/**
|
| 222 |
* Example output from the omniture.com site itself.
|
| 223 |
* Some of the paths may not be applicable for your site but at least it provides an example.
|
| 224 |
*/
|
| 225 |
|
| 226 |
/*
|
| 227 |
|
| 228 |
<!-- SITECATALYST CODE -->
|
| 229 |
<script language="javascript" src="/js/s_code_remote_h.js" type="text/javascript"></script>
|
| 230 |
<script language="javascript" type="text/javascript">
|
| 231 |
<!--
|
| 232 |
// Copyright 1997-2004 Omniture, Inc.
|
| 233 |
|
| 234 |
// PAGE SPECIFIC VIA ISOL G & H
|
| 235 |
|
| 236 |
var s_pageName='Omniture: Homepage';
|
| 237 |
var s_channel='Home';
|
| 238 |
var s_prop7='English';
|
| 239 |
s.pageName='Omniture: Homepage';
|
| 240 |
s.channel='Home';
|
| 241 |
s.prop6='English';
|
| 242 |
|
| 243 |
// END PAGE SPECIFIC VIA ISOL
|
| 244 |
|
| 245 |
// SiteCatalyst code version: G.7.
|
| 246 |
var s_server="www.omniture.com"
|
| 247 |
var s_campaign=""
|
| 248 |
var s_events=""
|
| 249 |
var s_products=""
|
| 250 |
var s_prop1="Non-Customer"
|
| 251 |
var s_prop15=""
|
| 252 |
var s_prop16=""
|
| 253 |
var s_eVar3 = ""
|
| 254 |
var s_eVar4 = ""
|
| 255 |
var s_eVar5 = ""
|
| 256 |
var s_eVar6 = ""
|
| 257 |
var s_eVar7 = ""
|
| 258 |
var s_eVar8 = ""
|
| 259 |
var s_eVar9 = ""
|
| 260 |
var s_eVar10 = ""
|
| 261 |
var s_eVar11 = ""
|
| 262 |
var s_eVar13 = ""
|
| 263 |
var s_eVar14 = ""
|
| 264 |
var s_eVar15 = ""
|
| 265 |
// END G.7 CODE IMPLEMENTATION
|
| 266 |
|
| 267 |
// H.1 CODE BEGIN
|
| 268 |
s.server="www.omniture.com"
|
| 269 |
s.campaign=""
|
| 270 |
s.events=""
|
| 271 |
s.products=""
|
| 272 |
s.prop1="Non-Customer"
|
| 273 |
s.prop3="Natural Search (All Other Engines)|"+s.pageName
|
| 274 |
s.prop5="Untracked"
|
| 275 |
s.prop14=""
|
| 276 |
s.prop15=""
|
| 277 |
s.prop16=""
|
| 278 |
s.prop17=""
|
| 279 |
s.prop18=""
|
| 280 |
s.prop19=""
|
| 281 |
s.prop20="Non-Customer"
|
| 282 |
s.prop21=""
|
| 283 |
s.prop22=""
|
| 284 |
s.prop23=""
|
| 285 |
s.prop24=""
|
| 286 |
s.prop25=""
|
| 287 |
s.prop26=""
|
| 288 |
s.prop27=""
|
| 289 |
s.prop28=""
|
| 290 |
s.prop30=""
|
| 291 |
s.prop32="67.41.129.163"
|
| 292 |
s.prop33=""
|
| 293 |
s.prop34=""
|
| 294 |
s.prop35=""
|
| 295 |
s.eVar7=""
|
| 296 |
s.eVar8=""
|
| 297 |
s.eVar9=""
|
| 298 |
s.eVar10=""
|
| 299 |
s.eVar11=""
|
| 300 |
s.eVar13=""
|
| 301 |
s.eVar28=""
|
| 302 |
s.eVar33=""
|
| 303 |
// H.1 CODE END
|
| 304 |
|
| 305 |
var s_code=s.t();if(s_code)document.write(s_code)
|
| 306 |
//-->
|
| 307 |
</script>
|
| 308 |
<script language="javascript" src="/js/s_code_remote_g.js" type="text/javascript"></script>
|
| 309 |
<noscript>
|
| 310 |
<img src="http://omniturecom.112.2O7.net/b/ss/omniturecom/1/H.7--NS/0" height="1" width="1" border="0" alt="" />
|
| 311 |
</noscript>
|
| 312 |
|
| 313 |
|
| 314 |
<!-- BANNER TRACKING IF ANY -->
|
| 315 |
<script language="javascript" src="/js/functions.js"></script>
|
| 316 |
<script language="javascript" src="/js/banner_track.js"></script>
|
| 317 |
<!-- END SITECATALYST CODE -->
|
| 318 |
|
| 319 |
*/
|