Ejemplo n.º 1
0
 /**
  * Track certain events on ElggEntity's
  *
  * @param string      $event  the event
  * @param string      $type   the type of the ElggEntity
  * @param \ElggEntity $object the entity for the event
  *
  * @return void
  */
 public static function events($event, $type, $object)
 {
     if (!$object instanceof \ElggEntity) {
         return;
     }
     if (!analytics_google_track_events_enabled()) {
         return;
     }
     switch ($object->getType()) {
         case 'object':
             analytics_track_event($object->getSubtype(), $event, $object->title);
             break;
         case 'group':
         case 'user':
             analytics_track_event($object->getType(), $event, $object->name);
             break;
     }
 }
Ejemplo n.º 2
0
<?php

// do we have the plugin configured correctly
if (!elgg_get_plugin_setting('analyticsSiteID', 'analytics')) {
    return;
}
$trackActions = analytics_google_track_actions_enabled();
$trackEvents = analytics_google_track_events_enabled();
// do we track actions/events
if (!$trackActions && !$trackEvents) {
    return;
}
?>
<script type='text/javascript' id='analytics_ajax_result'>

	$(document).ajaxSuccess(function(event, XMLHttpRequest, ajaxOptions) {
		
		elgg.get('analytics/ajax_success', {
			global: false,
			success: function(data) {
				if (data) {
					var temp = document.createElement('script');
					temp.setAttribute('type', 'text/javascript');
					temp.innerHTML = data;
					
					$('#analytics_ajax_result').after(temp);
				}
			}
		});
	});
</script>
Ejemplo n.º 3
0
/**
 * Get all the tracked Events in a Google Analytics format
 *
 * @return string
 */
function analytics_google_get_tracked_events()
{
    $output = '';
    if (!analytics_google_track_events_enabled()) {
        return $output;
    }
    if (empty($_SESSION['analytics']['events'])) {
        return $output;
    }
    foreach ($_SESSION['analytics']['events'] as $event) {
        $event_data = ['eventCategory' => $event['category'], 'eventAction' => $event['action']];
        if (!empty($event['label'])) {
            $event_data['eventLabel'] = $event['label'];
        }
        $output .= "ga('send', 'event', " . json_encode($event_data) . ");";
    }
    $_SESSION['analytics']['events'] = [];
    return $output;
}