How can I access the full referral path for one session/user through Google Reporting API V4 ? In this case in PHP.
For example we have following code found on Google's Reporting API V4 Documentation. (https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php)
function getReport(&$analytics) {
// Replace with your view ID, for example XXXX.
$VIEW_ID = "<REPLACE_WITH_VIEW_ID>";
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("7daysAgo");
$dateRange->setEndDate("today");
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setMetrics(array($sessions));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
This part is interesting:
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
Dimensions & Metrics Explorer (https://developers.google.com/analytics/devguides/reporting/core/dimsmets)
The path of the referring URL (e.g., document.referrer). If someone places on their webpage a link to the property, this is the path of the page containing the referring link.
The full referring URL including the hostname and path.
I am assuming that I have to go this way just fetching the desired dimensions/metrics:
$sessions->setExpression("ga:referralPath");
$sessions->setAlias("referral_path");
or
$sessions->setExpression("ga:fullReferrer");
$sessions->setAlias("full_referrer");
Would be this the right approach? If not is there another way to accomplish this?
And another question: When making a request with this metrics/dimensions:
$sessions->setExpression("ga:referralPath");
$sessions->setAlias("referral_path");
How Google knows from which session to take the referralPath?