I had a request last night about 'how is it done', and it makes sense to add the simple explanation in code here, to allow you folks to see that this is rather neutral in its approach.
In our test example we added some pieces of code to our redSLIDER component, and the result is that extension name, type (update/install), and version, is shown in analytics.
The base code part we added is the following in our component/admin/layouts/install_stats.php
Code: Select all
+<?php
+/**
+ * @package RedSLIDER
+ * @subpackage Layouts
+ *
+ * @copyright Copyright (C) 2014 redCOMPONENT.com. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+
+defined('JPATH_REDCORE') or die;
+$componentVersion = $displayData['comp_version'];
+$installType = $displayData['install_type'];
+$componentName = $displayData['comp_name'];
+?>
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-XXXXX-YY']);
+_gaq.push(['_trackEvent',
+ '<?php echo $installType ?>',
+ '<?php echo JText::_($componentName) ?>',
+ '<?php echo $componentVersion ?>']);
+(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>
Then to the component/admin/helpers/helper.php we added the following:
Code: Select all
+
+ /**
+ * Retrieve component infomation from manifest file
+ *
+ * @return array
+ */
+ public static function getComponentInfo()
+ {
+ $xmlfile = JPATH_SITE . '/administrator/components/com_redslider/redslider.xml';
+ $version = JText::_('COM_REDSLIDER_FILE_NOT_FOUND');
+ $info = array();
+ $info['version'] = $version;
+
+ if (file_exists($xmlfile))
+ {
+ $data = JApplicationHelper::parseXMLInstallFile($xmlfile);
+ $info['comp_version'] = $data['version'];
+ $info['comp_name'] = $data['name'];
+ }
+
+ return $info;
+ }
and finally for the view we added the following in component/admin/views/welcome/view.html.php
Code: Select all
defined('_JEXEC') or die;
+require_once JPATH_ADMINISTRATOR . '/components/com_redslider/helpers/helper.php';
+
/**
* Welcome View
*
@@ -36,10 +38,34 @@ class RedsliderViewWelcome extends RedsliderView
*/
public function display($tpl = null)
{
- $this->redsliderversion = $this->get('Version');
+ $displayData = RedsliderHelperHelper::getComponentInfo();
+ $this->redsliderversion = $displayData['comp_version'];
$this->installationType = JFactory::getApplication()->input->getString('type', '');
+ if ($this->installationType == 'update')
+ {
+ $displayData['install_type'] = 'Update';
+ }
+ else
+ {
+ $displayData['install_type'] = 'Install';
+ }
+
+ $this->installStatistics($displayData);
+
parent::display($tpl);
}
+
+ /**
+ * Render a GA script to track amount of installation
+ *
+ * @param array $displayData The display data
+ *
+ * @return void
+ */
+ public function installStatistics($displayData)
+ {
+ echo RLayoutHelper::render('install_stats', $displayData);
+ }
}
Hope this helps