Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
S
stats-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
stats-facil
Validations
eb820d0b
Valider
eb820d0b
rédigé
11 years ago
par
mattab
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Clarifying Visit Tracker hooks and code
parent
1c5c5e9d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
core/Tracker/Visit.php
+250
-232
250 ajouts, 232 suppressions
core/Tracker/Visit.php
avec
250 ajouts
et
232 suppressions
core/Tracker/Visit.php
+
250
−
232
Voir le fichier @
eb820d0b
...
@@ -121,9 +121,7 @@ class Visit implements VisitInterface
...
@@ -121,9 +121,7 @@ class Visit implements VisitInterface
$visitIsConverted
=
$someGoalsConverted
;
$visitIsConverted
=
$someGoalsConverted
;
// if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request
// if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request
if
(
!
$someGoalsConverted
)
{
if
(
!
$someGoalsConverted
)
{
Common
::
printDebug
(
'Invalid goal tracking request for goal id = '
.
$this
->
goalManager
->
idGoal
);
throw
new
\Exception
(
'Invalid goal tracking request for goal id = '
.
$this
->
goalManager
->
idGoal
);
unset
(
$this
->
goalManager
);
return
;
}
}
}
// normal page view, potentially triggering a URL matching goal
}
// normal page view, potentially triggering a URL matching goal
else
{
else
{
...
@@ -158,7 +156,7 @@ class Visit implements VisitInterface
...
@@ -158,7 +156,7 @@ class Visit implements VisitInterface
$idReferrerActionUrl
=
$this
->
visitorInfo
[
'visit_exit_idaction_url'
];
$idReferrerActionUrl
=
$this
->
visitorInfo
[
'visit_exit_idaction_url'
];
$idReferrerActionName
=
$this
->
visitorInfo
[
'visit_exit_idaction_name'
];
$idReferrerActionName
=
$this
->
visitorInfo
[
'visit_exit_idaction_name'
];
try
{
try
{
$this
->
handle
Known
Visit
(
$action
,
$visitIsConverted
);
$this
->
handle
Existing
Visit
(
$action
,
$visitIsConverted
);
if
(
!
is_null
(
$action
))
{
if
(
!
is_null
(
$action
))
{
$action
->
record
(
$this
->
visitorInfo
[
'idvisit'
],
$action
->
record
(
$this
->
visitorInfo
[
'idvisit'
],
$this
->
visitorInfo
[
'idvisitor'
],
$this
->
visitorInfo
[
'idvisitor'
],
...
@@ -171,7 +169,7 @@ class Visit implements VisitInterface
...
@@ -171,7 +169,7 @@ class Visit implements VisitInterface
// There is an edge case when:
// There is an edge case when:
// - two manual goal conversions happen in the same second
// - two manual goal conversions happen in the same second
// - which result in handle
Known
Visit throwing the exception
// - which result in handle
Existing
Visit throwing the exception
// because the UPDATE didn't affect any rows (one row was found, but not updated since no field changed)
// because the UPDATE didn't affect any rows (one row was found, but not updated since no field changed)
// - the exception is caught here and will result in a new visit incorrectly
// - the exception is caught here and will result in a new visit incorrectly
// In this case, we cancel the current conversion to be recorded:
// In this case, we cancel the current conversion to be recorded:
...
@@ -222,86 +220,15 @@ class Visit implements VisitInterface
...
@@ -222,86 +220,15 @@ class Visit implements VisitInterface
* 1) Insert the new action
* 1) Insert the new action
* 2) Update the visit information
* 2) Update the visit information
*
*
* This method triggers two events:
*
* Tracker.knownVisitorUpdate is triggered before the visit information is updated
* Event data is an array with the values to be updated (could be changed by plugins)
*
* Tracker.knownVisitorInformation is triggered after saving the new visit data
* Even data is an array with updated information about the visit
* @param Action $action
* @param Action $action
* @param $visitIsConverted
* @param $visitIsConverted
* @throws VisitorNotFoundInDb
* @throws VisitorNotFoundInDb
*/
*/
protected
function
handle
Known
Visit
(
$action
,
$visitIsConverted
)
protected
function
handle
Existing
Visit
(
$action
,
$visitIsConverted
)
{
{
// gather information that needs to be updated
$valuesToUpdate
=
array
();
$incrementActions
=
false
;
$sqlActionUpdate
=
''
;
if
(
$action
)
{
$idActionUrl
=
$action
->
getIdActionUrlForEntryAndExitIds
();
$idActionName
=
$action
->
getIdActionNameForEntryAndExitIds
();
$actionType
=
$action
->
getActionType
();
if
(
$idActionName
!==
false
)
{
$valuesToUpdate
[
'visit_exit_idaction_name'
]
=
$idActionName
;
}
if
(
$idActionUrl
!==
false
)
{
$valuesToUpdate
[
'visit_exit_idaction_url'
]
=
$idActionUrl
;
$incrementActions
=
true
;
}
if
(
$actionType
==
Action
::
TYPE_SITE_SEARCH
)
{
$sqlActionUpdate
.
=
"visit_total_searches = visit_total_searches + 1, "
;
$incrementActions
=
true
;
}
else
if
(
$actionType
==
Action
::
TYPE_EVENT
)
{
$sqlActionUpdate
.
=
"visit_total_events = visit_total_events + 1, "
;
$incrementActions
=
true
;
}
if
(
$incrementActions
)
{
$sqlActionUpdate
.
=
"visit_total_actions = visit_total_actions + 1, "
;
}
}
Common
::
printDebug
(
"Visit is known (IP = "
.
IP
::
N2P
(
$this
->
getVisitorIp
())
.
")"
);
Common
::
printDebug
(
"Visit is known (IP = "
.
IP
::
N2P
(
$this
->
getVisitorIp
())
.
")"
);
$datetimeServer
=
Tracker
::
getDatetimeFromTimestamp
(
$this
->
request
->
getCurrentTimestamp
());
$valuesToUpdate
=
$this
->
getExistingVisitFieldsToUpdate
(
$action
,
$visitIsConverted
);
$valuesToUpdate
[
'visit_last_action_time'
]
=
$datetimeServer
;
// Add 1 so it's always > 0
$visitTotalTime
=
1
+
$this
->
request
->
getCurrentTimestamp
()
-
$this
->
visitorInfo
[
'visit_first_action_time'
];
$valuesToUpdate
[
'visit_total_time'
]
=
self
::
cleanupVisitTotalTime
(
$visitTotalTime
);
// Goal conversion
if
(
$visitIsConverted
)
{
$valuesToUpdate
[
'visit_goal_converted'
]
=
1
;
// If a pageview and goal conversion in the same second, with previously a goal conversion recorded
// the request would not "update" the row since all values are the same as previous
// therefore the request below throws exception, instead we make sure the UPDATE will affect the row
$valuesToUpdate
[
'visit_total_time'
]
=
self
::
cleanupVisitTotalTime
(
$valuesToUpdate
[
'visit_total_time'
]
+
$this
->
goalManager
->
idGoal
// +2 to offset idgoal=-1 and idgoal=0
+
2
);
}
// Might update the idvisitor when it was forced or overwritten for this visit
if
(
strlen
(
$this
->
visitorInfo
[
'idvisitor'
])
==
Tracker
::
LENGTH_BINARY_ID
)
{
$valuesToUpdate
[
'idvisitor'
]
=
$this
->
visitorInfo
[
'idvisitor'
];
}
// Ecommerce buyer status
$valuesToUpdate
[
'visit_goal_buyer'
]
=
$this
->
goalManager
->
getBuyerType
(
$this
->
visitorInfo
[
'visit_goal_buyer'
]);
// Custom Variables overwrite previous values on each page view
$valuesToUpdate
=
array_merge
(
$valuesToUpdate
,
$this
->
visitorCustomVariables
);
/**
* This event is triggered before saving a known visitor. Use it to change any visitor information before
* the visitor is saved.
*/
Piwik
::
postEvent
(
'Tracker.knownVisitorUpdate'
,
array
(
&
$valuesToUpdate
));
$this
->
visitorInfo
[
'time_spent_ref_action'
]
=
$this
->
getTimeSpentReferrerAction
();
$this
->
visitorInfo
[
'time_spent_ref_action'
]
=
$this
->
getTimeSpentReferrerAction
();
...
@@ -310,43 +237,13 @@ class Visit implements VisitInterface
...
@@ -310,43 +237,13 @@ class Visit implements VisitInterface
$this
->
visitorInfo
[
$name
]
=
$value
;
$this
->
visitorInfo
[
$name
]
=
$value
;
}
}
// build sql query
$updateParts
=
$sqlBind
=
array
();
foreach
(
$valuesToUpdate
AS
$name
=>
$value
)
{
$updateParts
[]
=
$name
.
" = ?"
;
$sqlBind
[]
=
$value
;
}
$sqlQuery
=
"UPDATE "
.
Common
::
prefixTable
(
'log_visit'
)
.
"
SET
$sqlActionUpdate
"
.
implode
(
$updateParts
,
', '
)
.
"
WHERE idsite = ?
AND idvisit = ?"
;
array_push
(
$sqlBind
,
$this
->
request
->
getIdSite
(),
(
int
)
$this
->
visitorInfo
[
'idvisit'
]);
$result
=
Tracker
::
getDatabase
()
->
query
(
$sqlQuery
,
$sqlBind
);
$this
->
visitorInfo
[
'visit_last_action_time'
]
=
$this
->
request
->
getCurrentTimestamp
();
// Debug output
if
(
isset
(
$valuesToUpdate
[
'idvisitor'
]))
{
$valuesToUpdate
[
'idvisitor'
]
=
bin2hex
(
$valuesToUpdate
[
'idvisitor'
]);
}
Common
::
printDebug
(
'Updating existing visit: '
.
var_export
(
$valuesToUpdate
,
true
));
if
(
Tracker
::
getDatabase
()
->
rowCount
(
$result
)
==
0
)
{
Common
::
printDebug
(
"Visitor with this idvisit wasn't found in the DB."
);
Common
::
printDebug
(
"
$sqlQuery
--- "
);
Common
::
printDebug
(
$sqlBind
);
throw
new
VisitorNotFoundInDb
(
"The visitor with idvisitor="
.
bin2hex
(
$this
->
visitorInfo
[
'idvisitor'
])
.
" and idvisit="
.
$this
->
visitorInfo
[
'idvisit'
]
.
" wasn't found in the DB, we fallback to a new visitor"
);
}
/**
/**
*
After a known visitor is saved and updated by Piwik, this event is called. Useful for plugins that want to
*
This event is triggered before updating an existing visit's row. Use it to change any visitor information before
* register information about a
return
ing visitor
, or filter the existing information
.
*
the visitor is saved, or
register information about a
n exist
ing visitor.
*/
*/
Piwik
::
postEvent
(
'Tracker.knownVisitorInformation'
,
array
(
&
$this
->
visitorInfo
));
Piwik
::
postEvent
(
'Tracker.existingVisitInformation'
,
array
(
&
$valuesToUpdate
,
$this
->
visitorInfo
));
$this
->
updateExistingVisit
(
$valuesToUpdate
);
}
}
/**
/**
...
@@ -375,98 +272,19 @@ class Visit implements VisitInterface
...
@@ -375,98 +272,19 @@ class Visit implements VisitInterface
*/
*/
protected
function
handleNewVisit
(
$action
,
$visitIsConverted
)
protected
function
handleNewVisit
(
$action
,
$visitIsConverted
)
{
{
$actionType
=
$idActionName
=
$idActionUrl
=
false
;
if
(
$action
)
{
$idActionUrl
=
$action
->
getIdActionUrlForEntryAndExitIds
();
$idActionName
=
$action
->
getIdActionNameForEntryAndExitIds
();
$actionType
=
$action
->
getActionType
();
}
Common
::
printDebug
(
"New Visit (IP = "
.
IP
::
N2P
(
$this
->
getVisitorIp
())
.
")"
);
Common
::
printDebug
(
"New Visit (IP = "
.
IP
::
N2P
(
$this
->
getVisitorIp
())
.
")"
);
$daysSinceFirstVisit
=
$this
->
request
->
getDaysSinceFirstVisit
();
$this
->
visitorInfo
=
$this
->
getNewVisitorInformation
(
$action
);
$visitCount
=
$this
->
request
->
getVisitCount
();
$daysSinceLastVisit
=
$this
->
request
->
getDaysSinceLastVisit
();
$daysSinceLastOrder
=
$this
->
request
->
getDaysSinceLastOrder
();
$isReturningCustomer
=
(
$daysSinceLastOrder
!==
false
);
if
(
$daysSinceLastOrder
===
false
)
{
$daysSinceLastOrder
=
0
;
}
// User settings
$userInfo
=
$this
->
getUserSettingsInformation
();
// Referrer data
$referrer
=
new
Referrer
();
$referrerUrl
=
$this
->
request
->
getParam
(
'urlref'
);
$currentUrl
=
$this
->
request
->
getParam
(
'url'
);
$referrerInfo
=
$referrer
->
getReferrerInformation
(
$referrerUrl
,
$currentUrl
,
$this
->
request
->
getIdSite
());
$visitorReturning
=
$isReturningCustomer
?
2
/* Returning customer */
:
(
$visitCount
>
1
||
$this
->
isVisitorKnown
()
||
$daysSinceLastVisit
>
0
?
1
/* Returning */
:
0
/* New */
);
$defaultTimeOnePageVisit
=
Config
::
getInstance
()
->
Tracker
[
'default_time_one_page_visit'
];
/**
* Save the visitor
*/
$this
->
visitorInfo
=
array
(
'idsite'
=>
$this
->
request
->
getIdSite
(),
'visitor_localtime'
=>
$this
->
request
->
getLocalTime
(),
'idvisitor'
=>
$this
->
getVisitorIdcookie
(),
'visitor_returning'
=>
$visitorReturning
,
'visitor_count_visits'
=>
$visitCount
,
'visitor_days_since_last'
=>
$daysSinceLastVisit
,
'visitor_days_since_order'
=>
$daysSinceLastOrder
,
'visitor_days_since_first'
=>
$daysSinceFirstVisit
,
'visit_first_action_time'
=>
Tracker
::
getDatetimeFromTimestamp
(
$this
->
request
->
getCurrentTimestamp
()),
'visit_last_action_time'
=>
Tracker
::
getDatetimeFromTimestamp
(
$this
->
request
->
getCurrentTimestamp
()),
'visit_entry_idaction_url'
=>
(
int
)
$idActionUrl
,
'visit_entry_idaction_name'
=>
(
int
)
$idActionName
,
'visit_exit_idaction_url'
=>
(
int
)
$idActionUrl
,
'visit_exit_idaction_name'
=>
(
int
)
$idActionName
,
'visit_total_actions'
=>
in_array
(
$actionType
,
array
(
Action
::
TYPE_PAGE_URL
,
Action
::
TYPE_DOWNLOAD
,
Action
::
TYPE_OUTLINK
,
Action
::
TYPE_SITE_SEARCH
,
Action
::
TYPE_EVENT
))
?
1
:
0
,
// if visit starts with something else (e.g. ecommerce order), don't record as an action
'visit_total_searches'
=>
$actionType
==
Action
::
TYPE_SITE_SEARCH
?
1
:
0
,
'visit_total_events'
=>
$actionType
==
Action
::
TYPE_EVENT
?
1
:
0
,
'visit_total_time'
=>
self
::
cleanupVisitTotalTime
(
$defaultTimeOnePageVisit
),
'visit_goal_converted'
=>
$visitIsConverted
?
1
:
0
,
'visit_goal_buyer'
=>
$this
->
goalManager
->
getBuyerType
(),
'referer_type'
=>
$referrerInfo
[
'referer_type'
],
'referer_name'
=>
$referrerInfo
[
'referer_name'
],
'referer_url'
=>
$referrerInfo
[
'referer_url'
],
'referer_keyword'
=>
$referrerInfo
[
'referer_keyword'
],
'config_id'
=>
$userInfo
[
'config_id'
],
'config_os'
=>
$userInfo
[
'config_os'
],
'config_browser_name'
=>
$userInfo
[
'config_browser_name'
],
'config_browser_version'
=>
$userInfo
[
'config_browser_version'
],
'config_resolution'
=>
$userInfo
[
'config_resolution'
],
'config_pdf'
=>
$userInfo
[
'config_pdf'
],
'config_flash'
=>
$userInfo
[
'config_flash'
],
'config_java'
=>
$userInfo
[
'config_java'
],
'config_director'
=>
$userInfo
[
'config_director'
],
'config_quicktime'
=>
$userInfo
[
'config_quicktime'
],
'config_realplayer'
=>
$userInfo
[
'config_realplayer'
],
'config_windowsmedia'
=>
$userInfo
[
'config_windowsmedia'
],
'config_gears'
=>
$userInfo
[
'config_gears'
],
'config_silverlight'
=>
$userInfo
[
'config_silverlight'
],
'config_cookie'
=>
$userInfo
[
'config_cookie'
],
'location_ip'
=>
$this
->
getVisitorIp
(),
'location_browser_lang'
=>
$userInfo
[
'location_browser_lang'
],
);
// Add Custom variable key,value to the visitor array
// Add Custom variable key,value to the visitor array
$this
->
visitorInfo
=
array_merge
(
$this
->
visitorInfo
,
$this
->
visitorCustomVariables
);
$this
->
visitorInfo
=
array_merge
(
$this
->
visitorInfo
,
$this
->
visitorCustomVariables
);
$this
->
visitorInfo
[
'visit_goal_converted'
]
=
$visitIsConverted
?
1
:
0
;
$this
->
visitorInfo
[
'referer_name'
]
=
substr
(
$this
->
visitorInfo
[
'referer_name'
],
0
,
70
);
$this
->
visitorInfo
[
'referer_keyword'
]
=
substr
(
$this
->
visitorInfo
[
'referer_keyword'
],
0
,
255
);
$this
->
visitorInfo
[
'config_resolution'
]
=
substr
(
$this
->
visitorInfo
[
'config_resolution'
],
0
,
9
);
$extraInfo
=
array
(
$extraInfo
=
array
(
'UserAgent'
=>
$this
->
request
->
getUserAgent
(),
'UserAgent'
=>
$this
->
request
->
getUserAgent
(),
);
);
...
@@ -479,13 +297,14 @@ class Visit implements VisitInterface
...
@@ -479,13 +297,14 @@ class Visit implements VisitInterface
Piwik
::
postEvent
(
'Tracker.newVisitorInformation'
,
array
(
&
$this
->
visitorInfo
,
$extraInfo
));
Piwik
::
postEvent
(
'Tracker.newVisitorInformation'
,
array
(
&
$this
->
visitorInfo
,
$extraInfo
));
$this
->
request
->
overrideLocation
(
$this
->
visitorInfo
);
$this
->
request
->
overrideLocation
(
$this
->
visitorInfo
);
$this
->
printVisitorInformation
();
$debugVisitInfo
=
$this
->
visitorInfo
;
$idVisit
=
$this
->
insertNewVisit
(
$this
->
visitorInfo
);
$debugVisitInfo
[
'idvisitor'
]
=
bin2hex
(
$debugVisitInfo
[
'idvisitor'
]);
$debugVisitInfo
[
'config_id'
]
=
bin2hex
(
$debugVisitInfo
[
'config_id'
]);
$this
->
visitorInfo
[
'idvisit'
]
=
$idVisit
;
Common
::
printDebug
(
$debugVisitInfo
);
$this
->
visitorInfo
[
'visit_first_action_time'
]
=
$this
->
request
->
getCurrentTimestamp
();
$this
->
visitorInfo
[
'visit_last_action_time'
]
=
$this
->
request
->
getCurrentTimestamp
();
$this
->
saveVisitorInformation
();
}
}
static
private
function
cleanupVisitTotalTime
(
$t
)
static
private
function
cleanupVisitTotalTime
(
$t
)
...
@@ -501,31 +320,6 @@ class Visit implements VisitInterface
...
@@ -501,31 +320,6 @@ class Visit implements VisitInterface
return
$t
;
return
$t
;
}
}
/**
* Save new visitor information to log_visit table.
* Provides pre- and post- event hooks (Tracker.visitorInformation) for plugins
*/
protected
function
saveVisitorInformation
()
{
$this
->
visitorInfo
[
'location_browser_lang'
]
=
substr
(
$this
->
visitorInfo
[
'location_browser_lang'
],
0
,
20
);
$this
->
visitorInfo
[
'referer_name'
]
=
substr
(
$this
->
visitorInfo
[
'referer_name'
],
0
,
70
);
$this
->
visitorInfo
[
'referer_keyword'
]
=
substr
(
$this
->
visitorInfo
[
'referer_keyword'
],
0
,
255
);
$this
->
visitorInfo
[
'config_resolution'
]
=
substr
(
$this
->
visitorInfo
[
'config_resolution'
],
0
,
9
);
$fields
=
implode
(
", "
,
array_keys
(
$this
->
visitorInfo
));
$values
=
Common
::
getSqlStringFieldsArray
(
$this
->
visitorInfo
);
$sql
=
"INSERT INTO "
.
Common
::
prefixTable
(
'log_visit'
)
.
" (
$fields
) VALUES (
$values
)"
;
$bind
=
array_values
(
$this
->
visitorInfo
);
Tracker
::
getDatabase
()
->
query
(
$sql
,
$bind
);
$idVisit
=
Tracker
::
getDatabase
()
->
lastInsertId
();
$this
->
visitorInfo
[
'idvisit'
]
=
$idVisit
;
$this
->
visitorInfo
[
'visit_first_action_time'
]
=
$this
->
request
->
getCurrentTimestamp
();
$this
->
visitorInfo
[
'visit_last_action_time'
]
=
$this
->
request
->
getCurrentTimestamp
();
}
/**
/**
* Returns visitor cookie
* Returns visitor cookie
*
*
...
@@ -769,8 +563,6 @@ class Visit implements VisitInterface
...
@@ -769,8 +563,6 @@ class Visit implements VisitInterface
*
*
* The returned value is the window range (Min, max) that the matched visitor should fall within
* The returned value is the window range (Min, max) that the matched visitor should fall within
*
*
* Note: we must restrict in the future in case we import old data after having imported new data.
*
* @return array( datetimeMin, datetimeMax )
* @return array( datetimeMin, datetimeMax )
*/
*/
protected
function
getWindowLookupThisVisit
()
protected
function
getWindowLookupThisVisit
()
...
@@ -867,7 +659,6 @@ class Visit implements VisitInterface
...
@@ -867,7 +659,6 @@ class Visit implements VisitInterface
'config_cookie'
=>
$plugin_Cookie
,
'config_cookie'
=>
$plugin_Cookie
,
'location_browser_lang'
=>
$browserLang
,
'location_browser_lang'
=>
$browserLang
,
);
);
return
$this
->
userSettingsInformation
;
return
$this
->
userSettingsInformation
;
}
}
...
@@ -947,4 +738,231 @@ class Visit implements VisitInterface
...
@@ -947,4 +738,231 @@ class Visit implements VisitInterface
return
false
;
return
false
;
}
}
/**
* @return mixed
*/
protected
function
insertNewVisit
(
$visit
)
{
$fields
=
implode
(
", "
,
array_keys
(
$visit
));
$values
=
Common
::
getSqlStringFieldsArray
(
$visit
);
$sql
=
"INSERT INTO "
.
Common
::
prefixTable
(
'log_visit'
)
.
" (
$fields
) VALUES (
$values
)"
;
$bind
=
array_values
(
$visit
);
Tracker
::
getDatabase
()
->
query
(
$sql
,
$bind
);
$idVisit
=
Tracker
::
getDatabase
()
->
lastInsertId
();
return
$idVisit
;
}
/**
* @param $valuesToUpdate
* @throws VisitorNotFoundInDb
*/
protected
function
updateExistingVisit
(
$valuesToUpdate
)
{
$sqlQuery
=
"UPDATE "
.
Common
::
prefixTable
(
'log_visit'
)
.
"
SET %s
WHERE idsite = ?
AND idvisit = ?"
;
// build sql query
$updateParts
=
$sqlBind
=
array
();
foreach
(
$valuesToUpdate
AS
$name
=>
$value
)
{
// Case where bind parameters don't work
if
(
strpos
(
$value
,
$name
)
!==
false
)
{
//$name = 'visit_total_events'
//$value = 'visit_total_events + 1';
$updateParts
[]
=
"
$name
=
$value
"
;
}
else
{
$updateParts
[]
=
$name
.
" = ?"
;
$sqlBind
[]
=
$value
;
}
}
$sqlQuery
=
sprintf
(
$sqlQuery
,
implode
(
$updateParts
,
', '
)
);
array_push
(
$sqlBind
,
$this
->
request
->
getIdSite
(),
(
int
)
$this
->
visitorInfo
[
'idvisit'
]);
$result
=
Tracker
::
getDatabase
()
->
query
(
$sqlQuery
,
$sqlBind
);
$this
->
visitorInfo
[
'visit_last_action_time'
]
=
$this
->
request
->
getCurrentTimestamp
();
// Debug output
if
(
isset
(
$valuesToUpdate
[
'idvisitor'
]))
{
$valuesToUpdate
[
'idvisitor'
]
=
bin2hex
(
$valuesToUpdate
[
'idvisitor'
]);
}
Common
::
printDebug
(
'Updating existing visit: '
.
var_export
(
$valuesToUpdate
,
true
));
if
(
Tracker
::
getDatabase
()
->
rowCount
(
$result
)
==
0
)
{
Common
::
printDebug
(
"Visitor with this idvisit wasn't found in the DB."
);
Common
::
printDebug
(
"
$sqlQuery
--- "
);
Common
::
printDebug
(
$sqlBind
);
throw
new
VisitorNotFoundInDb
(
"The visitor with idvisitor="
.
bin2hex
(
$this
->
visitorInfo
[
'idvisitor'
])
.
" and idvisit="
.
$this
->
visitorInfo
[
'idvisit'
]
.
" wasn't found in the DB, we fallback to a new visitor"
);
}
}
protected
function
printVisitorInformation
()
{
$debugVisitInfo
=
$this
->
visitorInfo
;
$debugVisitInfo
[
'idvisitor'
]
=
bin2hex
(
$debugVisitInfo
[
'idvisitor'
]);
$debugVisitInfo
[
'config_id'
]
=
bin2hex
(
$debugVisitInfo
[
'config_id'
]);
Common
::
printDebug
(
$debugVisitInfo
);
}
protected
function
getNewVisitorInformation
(
$action
,
$visitIsConverted
)
{
$actionType
=
$idActionName
=
$idActionUrl
=
false
;
if
(
$action
)
{
$idActionUrl
=
$action
->
getIdActionUrlForEntryAndExitIds
();
$idActionName
=
$action
->
getIdActionNameForEntryAndExitIds
();
$actionType
=
$action
->
getActionType
();
}
$daysSinceFirstVisit
=
$this
->
request
->
getDaysSinceFirstVisit
();
$visitCount
=
$this
->
request
->
getVisitCount
();
$daysSinceLastVisit
=
$this
->
request
->
getDaysSinceLastVisit
();
$daysSinceLastOrder
=
$this
->
request
->
getDaysSinceLastOrder
();
$isReturningCustomer
=
(
$daysSinceLastOrder
!==
false
);
if
(
$daysSinceLastOrder
===
false
)
{
$daysSinceLastOrder
=
0
;
}
// User settings
$userInfo
=
$this
->
getUserSettingsInformation
();
// Referrer data
$referrer
=
new
Referrer
();
$referrerUrl
=
$this
->
request
->
getParam
(
'urlref'
);
$currentUrl
=
$this
->
request
->
getParam
(
'url'
);
$referrerInfo
=
$referrer
->
getReferrerInformation
(
$referrerUrl
,
$currentUrl
,
$this
->
request
->
getIdSite
());
$visitorReturning
=
$isReturningCustomer
?
2
/* Returning customer */
:
(
$visitCount
>
1
||
$this
->
isVisitorKnown
()
||
$daysSinceLastVisit
>
0
?
1
/* Returning */
:
0
/* New */
);
$defaultTimeOnePageVisit
=
Config
::
getInstance
()
->
Tracker
[
'default_time_one_page_visit'
];
return
array
(
'idsite'
=>
$this
->
request
->
getIdSite
(),
'visitor_localtime'
=>
$this
->
request
->
getLocalTime
(),
'idvisitor'
=>
$this
->
getVisitorIdcookie
(),
'visitor_returning'
=>
$visitorReturning
,
'visitor_count_visits'
=>
$visitCount
,
'visitor_days_since_last'
=>
$daysSinceLastVisit
,
'visitor_days_since_order'
=>
$daysSinceLastOrder
,
'visitor_days_since_first'
=>
$daysSinceFirstVisit
,
'visit_first_action_time'
=>
Tracker
::
getDatetimeFromTimestamp
(
$this
->
request
->
getCurrentTimestamp
()),
'visit_last_action_time'
=>
Tracker
::
getDatetimeFromTimestamp
(
$this
->
request
->
getCurrentTimestamp
()),
'visit_entry_idaction_url'
=>
(
int
)
$idActionUrl
,
'visit_entry_idaction_name'
=>
(
int
)
$idActionName
,
'visit_exit_idaction_url'
=>
(
int
)
$idActionUrl
,
'visit_exit_idaction_name'
=>
(
int
)
$idActionName
,
'visit_total_actions'
=>
in_array
(
$actionType
,
array
(
Action
::
TYPE_PAGE_URL
,
Action
::
TYPE_DOWNLOAD
,
Action
::
TYPE_OUTLINK
,
Action
::
TYPE_SITE_SEARCH
,
Action
::
TYPE_EVENT
))
?
1
:
0
,
// if visit starts with something else (e.g. ecommerce order), don't record as an action
'visit_total_searches'
=>
$actionType
==
Action
::
TYPE_SITE_SEARCH
?
1
:
0
,
'visit_total_events'
=>
$actionType
==
Action
::
TYPE_EVENT
?
1
:
0
,
'visit_total_time'
=>
self
::
cleanupVisitTotalTime
(
$defaultTimeOnePageVisit
),
'visit_goal_buyer'
=>
$this
->
goalManager
->
getBuyerType
(),
'referer_type'
=>
$referrerInfo
[
'referer_type'
],
'referer_name'
=>
$referrerInfo
[
'referer_name'
],
'referer_url'
=>
$referrerInfo
[
'referer_url'
],
'referer_keyword'
=>
$referrerInfo
[
'referer_keyword'
],
'config_id'
=>
$userInfo
[
'config_id'
],
'config_os'
=>
$userInfo
[
'config_os'
],
'config_browser_name'
=>
$userInfo
[
'config_browser_name'
],
'config_browser_version'
=>
$userInfo
[
'config_browser_version'
],
'config_resolution'
=>
$userInfo
[
'config_resolution'
],
'config_pdf'
=>
$userInfo
[
'config_pdf'
],
'config_flash'
=>
$userInfo
[
'config_flash'
],
'config_java'
=>
$userInfo
[
'config_java'
],
'config_director'
=>
$userInfo
[
'config_director'
],
'config_quicktime'
=>
$userInfo
[
'config_quicktime'
],
'config_realplayer'
=>
$userInfo
[
'config_realplayer'
],
'config_windowsmedia'
=>
$userInfo
[
'config_windowsmedia'
],
'config_gears'
=>
$userInfo
[
'config_gears'
],
'config_silverlight'
=>
$userInfo
[
'config_silverlight'
],
'config_cookie'
=>
$userInfo
[
'config_cookie'
],
'location_ip'
=>
$this
->
getVisitorIp
(),
'location_browser_lang'
=>
$userInfo
[
'location_browser_lang'
],
);
}
/**
* Gather fields=>values that needs to be updated for the existing visit in log_visit
*
* @param $action
* @param $visitIsConverted
* @return array
*/
protected
function
getExistingVisitFieldsToUpdate
(
$action
,
$visitIsConverted
)
{
$valuesToUpdate
=
array
();
if
(
$action
)
{
$idActionUrl
=
$action
->
getIdActionUrlForEntryAndExitIds
();
$idActionName
=
$action
->
getIdActionNameForEntryAndExitIds
();
$actionType
=
$action
->
getActionType
();
if
(
$idActionName
!==
false
)
{
$valuesToUpdate
[
'visit_exit_idaction_name'
]
=
$idActionName
;
}
$incrementActions
=
false
;
if
(
$idActionUrl
!==
false
)
{
$valuesToUpdate
[
'visit_exit_idaction_url'
]
=
$idActionUrl
;
$incrementActions
=
true
;
}
if
(
$actionType
==
Action
::
TYPE_SITE_SEARCH
)
{
$valuesToUpdate
[
'visit_total_searches'
]
=
'visit_total_searches + 1'
;
$incrementActions
=
true
;
}
else
if
(
$actionType
==
Action
::
TYPE_EVENT
)
{
$valuesToUpdate
[
'visit_total_events'
]
=
'visit_total_events + 1'
;
$incrementActions
=
true
;
}
if
(
$incrementActions
)
{
$valuesToUpdate
[
'visit_total_actions'
]
=
'visit_total_actions + 1'
;
}
}
$datetimeServer
=
Tracker
::
getDatetimeFromTimestamp
(
$this
->
request
->
getCurrentTimestamp
());
$valuesToUpdate
[
'visit_last_action_time'
]
=
$datetimeServer
;
// Add 1 so it's always > 0
$visitTotalTime
=
1
+
$this
->
request
->
getCurrentTimestamp
()
-
$this
->
visitorInfo
[
'visit_first_action_time'
];
$valuesToUpdate
[
'visit_total_time'
]
=
self
::
cleanupVisitTotalTime
(
$visitTotalTime
);
// Goal conversion
if
(
$visitIsConverted
)
{
$valuesToUpdate
[
'visit_goal_converted'
]
=
1
;
// If a pageview and goal conversion in the same second, with previously a goal conversion recorded
// the request would not "update" the row since all values are the same as previous
// therefore the request below throws exception, instead we make sure the UPDATE will affect the row
$valuesToUpdate
[
'visit_total_time'
]
=
self
::
cleanupVisitTotalTime
(
$valuesToUpdate
[
'visit_total_time'
]
+
$this
->
goalManager
->
idGoal
// +2 to offset idgoal=-1 and idgoal=0
+
2
);
}
// Might update the idvisitor when it was forced or overwritten for this visit
if
(
strlen
(
$this
->
visitorInfo
[
'idvisitor'
])
==
Tracker
::
LENGTH_BINARY_ID
)
{
$valuesToUpdate
[
'idvisitor'
]
=
$this
->
visitorInfo
[
'idvisitor'
];
}
// Ecommerce buyer status
$valuesToUpdate
[
'visit_goal_buyer'
]
=
$this
->
goalManager
->
getBuyerType
(
$this
->
visitorInfo
[
'visit_goal_buyer'
]);
// Custom Variables overwrite previous values on each page view
$valuesToUpdate
=
array_merge
(
$valuesToUpdate
,
$this
->
visitorCustomVariables
);
return
$valuesToUpdate
;
}
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter