| Current Path : /home/pteabiscqq/www/plugins/system/lab5_cookie_commander/analytics/ |
| Current File : /home/pteabiscqq/www/plugins/system/lab5_cookie_commander/analytics/inc.piwik.php |
<?php defined('_JEXEC') or die();
/////////////////////////////////////////////////////////////////////////////////////////////
/**
* Cookie Commander
*
* @author : Lab5 - Dennis Riegelsberger
* @authorUrl : https://lab5.ch
* @copyright : Copyright (C) 2018+ Lab5 - Dennis Riegelsberger. All rights reserved.
* @license : GNU/GPL General Public License version 2 or later
* @project : https://lab5.ch/cookie-commander
* @on JED : https://extensions.joomla.org/extensions/extension/site-management/cookie-control/lab5-cookie-commander/
*
* Built with <3
* Lab5
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @CHANGELOG :
*/
/////////////////////////////////////////////////////////////////////////////////////////////
require 'piwik/PiwikTracker.php';
/////////////////////////////////////////////////////////////////////////////////////////////
$getUserRealIP = function(){
/*
Sometimes REMOTE_ADDR does not returns the correct IP address of the user. The reason behind this can be the use of a proxy etc.. In that situation, use the following code to get real IP address of user in PHP.
*/
// Get real visitor IP behind CloudFlare network
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$client = @$_SERVER['HTTP_CLIENT_IP']; //ip from share internet
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; //ip passed from proxy
$remote = $_SERVER['REMOTE_ADDR']; // standart : the remote address
if( filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}
return $ip;
};
/////////////////////////////////////////////////////////////////////////////////////////////
/* * * * * * * * * * * * *
https://forum.matomo.org/t/campaign-tracking-via-php-tracker-api/4650/2
https://matomo.org/docs/tracking-api/#toc-how-to-use-the-php-tracker-api-example
* * * * * * * * * * * * */
$lang = JFactory::getLanguage();
$lang = $lang->getTag();
$app = JFactory::getApplication();
if(!isset($doc)) $doc = JFactory::getDocument();
///////////
$jcomponent = substr($app->input->get('option'), 0);
$jview = $app->input->get('view');
///////////
PiwikTracker::$DEBUG_LAST_REQUESTED_URL = true;
$piwik = new PiwikTracker( self::$xstor->cooco->piwikID, self::$xstor->cooco->piwikAddress );
if( self::$xstor->cooco->piwikAUTHtoken ){
// Some Tracking API functionality requires authentication ( e.g. setIP() ), using either the Super User token_auth, or a user with 'admin' or write access access to the website.
$piwik->setTokenAuth( self::$xstor->cooco->piwikAUTHtoken );
}
$realIP = $getUserRealIP();
//$piwik->ip = $_SERVER['REMOTE_ADDR'];
// $piwik->DEBUG_APPEND_URL = 'http://somethinglab5.ch';
$url = JFactory::getURI()->toString();
$urlr = (isset($_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : '';
$user = JFactory::getUser();
// $url = $_SERVER['HTTP_REFERER'];
$uid = md5($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR']);
$doctitle = $doc->getTitle();
///////////
if(self::$xstor->cooco->donottrack){
// NOT YET IMPLEMENTED FOR PHP-TRACKER SO FAR ...
}
///////////
if( self::$xstor->cooco->piwikEmbedMode == 3 ){ // NOT Stealth-Mode
//
}
///////////
// $piwik->disableCookieSupport(); // By default, PiwikTracker will read first party cookies from the request and write updated cookies in the response (using setrawcookie).
///////////
/////////////////////////////////////////////////////////////////////////////////////////////
// https://developer.matomo.org/api-reference/PHP-Piwik-Tracker
/////////////////////////////////////////////////////////////////////////////////////////////
// $piwik->setPageCharset(); // By default, Matomo expects utf-8 encoded values, for example for the page $piwik->URL parameter values, Page Title, etc.
$piwik->setUrl( $url ); // Sets the current URL being tracked
$piwik->setUrlReferrer($urlr); // Sets the URL referrer used to track Referrers details for new visits.
$piwik->setGenerationTime(time()); // Sets the time that generating the document on the server side took.
// $piwik->setAttributionInfo(); // Sets the attribution information to the visit, so that subsequent Goal conversions are properly attributed to the right Referrer URL, timestamp, Campaign Name & Keyword.
$piwik->setCustomVariable( 1, 'loggedin', (( $user->guest) ? 0 : 1) ); // Sets Visit Custom Variable.
$piwik->setCustomVariable( 2, 'component', $jcomponent ); // Sets Visit Custom Variable.
$piwik->setCustomVariable( 3, 'component_view', $jview ); // Sets Visit Custom Variable.
$piwik->setCustomVariable( 4, 'language', $lang ); // Sets Visit Custom Variable.
/* * * * * * * * * * * * * * * * * * * * *
$piwik->getCustomVariable(); // Returns the currently assigned Custom Variable.
$piwik->clearCustomVariables(); // Clears any Custom Variable that may be have been set.
$piwik->setCustomTrackingParameter(); // Sets a custom tracking parameter.
$piwik->clearCustomTrackingParameters(); // Clear / reset all previously set custom tracking parameters.
$piwik->setNewVisitorId(); // Sets the current visitor ID to a random new one.
$piwik->setIdSite(); // Sets the current site ID.
$piwik->setBrowserLanguage(); // Sets the Browser language.
$piwik->setUserAgent(); // Sets the user agent, used to detect OS and browser.
$piwik->setCountry(); // Sets the country of the visitor.
$piwik->setRegion(); // Sets the region of the visitor.
$piwik->setCity(); // Sets the city of the visitor.
$piwik->setLatitude(); // Sets the latitude of the visitor.
$piwik->setLongitude(); // Sets the longitude of the visitor.
$piwik->enableBulkTracking(); // Enables the bulk request feature.
$piwik->enableCookies(); // Enable Cookie Creation - this will cause a first party VisitorId cookie to be set when the VisitorId is set or reset
/* * * * * * * * * * * * * * * * * * * * */
$piwik->disableSendImageResponse(); // If image response is disabled Matomo will respond with a HTTP 204 header instead of responding with a gif.
/* * * * * * * * * * * * * * * * * * * * */
// Specify an API token with at least Write permission, so the Visitor IP address can be recorded
// Learn more about token_auth: https://matomo.org/faq/general/faq_114/
$piwik->setIp($realIP); // Overrides IP address - if we dont do this, strangely the IP of the server the Website is hosted on will be recorded.
// $piwik->setUserId($uid); // Force the action to be recorded for a specific User.
$piwik->doTrackPageView( $doctitle ); // Tracks a page view
/* * * * * * * * * * * * * * * * * * * * *
[ --- INTERESTING !!! ---> ]
$piwik->doTrackEvent(); // Tracks an event
[ --- INTERESTING !!! ---> ]
$piwik->doTrackContentImpression(); // Tracks a content impression
$piwik->doTrackContentInteraction(); // Tracks a content interaction.
[ --- INTERESTING !!! ---> ]
$piwik->doTrackSiteSearch(); // Tracks an internal Site Search query, and optionally tracks the Search Category, and Search results Count.
[ --- INTERESTING !!! ---> ]
$piwik->doTrackGoal(); // Records a Goal conversion
[ --- INTERESTING !!! ---> ]
$piwik->doTrackAction(); // Tracks a download or outlink
$piwik->addEcommerceItem(); // Adds an item in the Ecommerce order.
doTrackEcommerceCartUpdate(); // Tracks a Cart Update (add item, remove item, update item).
$piwik->doBulkTrack(); // Sends all stored tracking actions at once.
$piwik->doTrackEcommerceOrder(); // Tracks an Ecommerce order.
$piwik->doPing(); // Sends a ping request.
$piwik->setEcommerceView(); // Sets the current page view as an item (product) page view, or an Ecommerce Category page view.
$piwik->getUrlTrackPageView(); // Builds URL to track a page view. ( = URL sent to Piwik, for the Tracking action )
$piwik->getUrlTrackEvent(); // Builds URL to track a custom event.
$piwik->getUrlTrackContentImpression(); // Builds URL to track a content impression.
$piwik->getUrlTrackContentInteraction(); // Builds URL to track a content impression.
$piwik->getUrlTrackSiteSearch(); // Builds URL to track a site search.
$piwik->getUrlTrackGoal(); // Builds URL to track a goal with idGoal and revenue.
$piwik->getUrlTrackAction(); // Builds URL to track a new action.
$piwik->setForceVisitDateTime(); // Overrides server date and time for the tracking requests.
$piwik->setForceNewVisit(); // Forces Matomo to create a new visit for the tracking request.
$piwik->setIp(); // Overrides IP address
* * * * * * * * * * * * * * * * * * * * */
// $piwik->setIp($_SERVER['REMOTE_ADDR']); // Overrides IP address
// $piwik->setUserId($uid); // Force the action to be recorded for a specific User.
/* * * * * * * * * * * * * * * * * * * * *
$piwik->getUserIdHashed(); // Hash function used internally by Matomo to hash a User ID into the Visitor ID.
// Anmerkung : $piwik->getUserIdHashed($piwik->getUserId()) === $piwik->getVisitorId();
$piwik->setVisitorId(); // Forces the requests to be recorded for the specified Visitor ID.
$piwik->getVisitorId(); // If the user initiating the request has the Matomo first party cookie, this function will try and return the ID parsed from this first party cookie (found in $_COOKIE).
$piwik->getUserAgent(); // Returns the currently set user agent.
$piwik->getIp(); // Returns the currently set IP address.
$piwik->getUserId(); // Returns the User ID string, which may have been set via: $v->setUserId('username@example.org');
$piwik->deleteCookies(); // Deletes all first party cookies from the client
$piwik->getAttributionInfo(); // Returns the currently assigned Attribution Information stored in a first party cookie.
$piwik->setTokenAuth(); // Some Tracking API functionality requires express authentication, using either the Super User token_auth, or a user with 'admin' access to the website.
$piwik->setLocalTime(); // Sets local visitor time
$piwik->setResolution(); // Sets user resolution width and height.
setBrowserHasCookies(); // ash; Sets if the browser supports cookies This is reported in "List of plugins" report in Matomo.
[ --- INTERESTING !!! ---> ]
$piwik->setDebugStringAppend(); // Will append a custom string at the end of the Tracking request.
$piwik->setPlugins(); // Sets visitor browser supported plugins
$piwik->disableCookieSupport(); // By default, PiwikTracker will read first party cookies from the request and write updated cookies in the response (using setrawcookie).
$piwik->getRequestTimeout(); // Returns the maximum number of seconds the tracker will spend waiting for a response from Matomo.
$piwik->setRequestTimeout(); // Sets the maximum number of seconds that the tracker will spend waiting for a response from Matomo.
$piwik->setProxy(); // If a proxy is needed to look up the address of the Matomo site, set it with this
$piwik->setOutgoingTrackerCookie(); // Sets a cookie to be sent to the tracking server.
$piwik->getIncomingTrackerCookie(); // Gets a cookie which was set by the tracking server.
* * * * * * * * * * * * * * * * * * * * */
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////