Для полноценной работы компонента AG Google Analytics необходимо в код трекера добавить 2 переменные. Это можно сделать с помощью плагина plug-plg_ag_google_analytics или в ручную.
Google Analytics Tracking API: Basic Configuration
Method Details
_setCustomVar(index, name, value, opt_scope)
Returns the visitor level custom variable assigned for the specified index.
pageTracker._setCustomVar(
1, // This custom var is set to slot #1
"Section", // The top-level name for your online content categories
"Life & Style", // Sets the value of "Section" to "Life & Style" // for this particular aricle
3 // Sets the scope to page-level
);
pameters
Int index The slot used for the custom variable. Possible values are 1-5, inclusive.
String name The name for the custom variable.
String value The value for the custom variable.
Int opt_scope The scope used for the custom variable. Possible values are 1 for visitor-level, 2 for sesson-level, and 3 for page-level.
return
Boolean This method returns true if the custom variable has been set successfully, and false if it has not (e.g. if your name/value string length exceeds 64 bytes, or if you use an incorrect slot)..
Полный код для трекинга Имен пользователей и ip посетителей
Для традиционного метода:
<?php $clientIPaddress = $_SERVER['REMOTE_ADDR'];
$user =& JFactory::getUser(); ?>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("XX-XXXXXXX-X");
pageTracker._setCustomVar( 1, "user_ip", "<?php echo $clientIPaddress ; ?>", 1 );
<?php if( $user->guest == 0 ) { ?>
pageTracker._setCustomVar( 2, "joomla_user", "<?php echo $user->name; ?>", 1 );
<?php } ?>
pageTracker._trackPageview();
} catch(err) {}
</script>
Для асинхронного метода:
<?php $clientIPaddress = $_SERVER['REMOTE_ADDR'];
$user =& JFactory::getUser(); ?>
<script type="text/javascript">
var _gaq = _gaq || [];
<script type="text/javascript">
try {
_gaq.push(['_setAccount', 'XX-XXXXXXX-X']);
_gaq.push(['_setCustomVar', 1, 'user_ip', '<?php echo $clientIPaddress ; ?>", 1 ]);
<?php if( $user->guest == 0 ) { ?>
_gaq.push(['_setCustomVar', 2, "joomla_user", "<?php echo $user->name; ?>", 1 ]);
<?php } ?>
_gaq.push(['_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>
|