Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oranblackwell/7821493 to your computer and use it in GitHub Desktop.
Save oranblackwell/7821493 to your computer and use it in GitHub Desktop.
Last edited 2011 WP functions needed. Pass to _gaq by setting _setCustomerVar.
//header.php version - Place just before </head>
##########################################
<?php
require_once($CFG->dirroot.'/blocks/sb_training_tools/lib/locallib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
/**
*
* Retrieve the displayed user's details
*/
if (!$user = get_record('user', 'id', $USER->id)) {
}
//Load custom profile fields data
profile_load_data($user);
add_sb_details_to_user($user);
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-123456-1'],
['_setCustomVar',1,'User Name','<?php if(isset($user->firstname) && isset($user->lastname)) echo $user->firstname.' '.$user->lastname;?>',3],
['_setCustomVar',2,'Department','<?php if(isset($user->department)) echo $user->department; ?>',3],
['_setCustomVar',3,'Location','<?php if(isset($user->location)) echo $user->location; ?>',3],
['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
##########################################
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1234567-1'],
['_setCustomVar',1,'Permission Level','<?php if(isset($_SESSION['permission'])) echo $_SESSION['permission']; else echo 'visitor';?>',3],
['_setCustomVar',2,'Company Name','<?php if(isset($_SESSION['company_name'])) echo $_SESSION['company_name']; else echo 'visitor';?>',3],
['_setCustomVar',3,'User Name','<?php if(isset($_SESSION['username'])) echo $_SESSION['username']; else echo 'visitor';?>',3],
['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php
//Place in Footer
require_once($CFG->dirroot.'/blocks/sb_training_tools/lib/locallib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
if ($user = get_record('user', 'id', $USER->id)) {
//Load custom profile fields data
profile_load_data($user);
add_sb_details_to_user($user);
}
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1234567-1'],
['_setCustomVar',1,'User Name','<?php if(isset($user->firstname) && isset($user->lastname)) echo $user->firstname.' '.$user->lastname;?>',3],
['_setCustomVar',2,'Department','<?php if(isset($user->department)) echo $user->department; ?>',3],
['_setCustomVar',3,'Location','<?php if(isset($user->location)) echo $user->location; ?>',3],
['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment