I am setting up a reporting script which gets data from google analytics .I am adding three dimensions to get the data but one of the those dimensions is custom dimension named test_dimension. When i set this dimension i get this error.
Unknown dimension(s): test_dimension
I tried the developer API but cannot get the expected results
https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=custom_variables_or_columns&jump=ga_dimensionxx
$custom = new Google_Service_AnalyticsReporting_Dimension();
$custom->setName("test_dimension");
$campaign = new Google_Service_AnalyticsReporting_Dimension();
$campaign->setName("ga:campaign");
$sourceMedium = new Google_Service_AnalyticsReporting_Dimension();
$sourceMedium->setName("ga:sourceMedium");
$request->setDimensions(array($custom,$campaign,$sourceMedium));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
I expect the output with the applied dimensions. If i remove the custom dimension the code works.
You'll need to use the index of the custom dimension (e.g. ga:dimension03) instead of its name. The index is visible in the property's admin settings under Custom Definitions.
Related
I'm trying to automatise the Google analytics report of our app websites, something like 55 or so.
What I need is:
avg time
users new/returning
direct/referral/search
users per day (based on 1st of the month to the last day)
I'm using the guide from Google
https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/web-php
my function for the report is something like this:
function getReport($analytics) {
// Replace with your view ID, for example XXXX.
$VIEW_ID = "XXXX";
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("2019-05-01");
$dateRange->setEndDate("2019-05-31");
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
$users = new Google_Service_AnalyticsReporting_Metric();
$users->setExpression("ga:users");
$users->setAlias("users");
$newSessions = new Google_Service_AnalyticsReporting_Metric();
$newSessions->setExpression("ga:percentNewSessions");
$newSessions->setAlias("newSessions");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setMetrics(array($sessions,$users,$newSessions));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
Of course is not the definitely one I'm just experimenting with some metrics.
I was trying to get back the users per day like this
$monthusers = new Google_Service_AnalyticsReporting_Metric();
$monthusers->setExpression("ga:30dayUsers");
$monthusers->setAlias("monthusers");
and then in the request
$request->setMetrics(array($sessions,$users,$newSessions,$monthusers));
but it throw a 500 error, any idea on how to get back the users per day? and based on the:
$dateRange->setStartDate("2019-05-01");
$dateRange->setEndDate("2019-05-31");
As per mentioned in the Dimensions & Metrics Explorer for the metric "ga:30dayUsers":
At least one of ga:nthDay, ga:date, or ga:day must be specified as a
dimension to query this metric.
You could use the ga:day dimension into your report request to solve the issue:
$day = new Google_Service_AnalyticsReporting_Dimension();
$day->setName("ga:day");
$request->setDimensions(array($day));
Currently I'm using the Google Sheets API via their PHP library to build a dynamic spreadsheet. I've set validation rules on a spreadsheet, specifically to create a dropdown list of states to select.
I have since updated the spreadsheet to have the state dropdown list in a different column. Upon doing this however, it seems the DataValidationRule that was set for the previous column, is still there.
I've attempted to create a method to REMOVE all validation from my sheet before re-applying any validation I want, but it does not seem to be working.
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#conditiontype
When setting a Condition Type, I'd like to revert the validation back to CONDITION_TYPE_UNSPECIFIED, however the API simply returns an error if I do so. I've attempted to use others such as ONE_OF_LIST, but then every cell errors saying:
Invalid: Input must be an item on specified list
Which makes sense, considering there is no list being generated (nor do I want one).
The rest of the columns can be any sort of combination of numbers/dates/text so I'd like to simply remove all validation before applying validation again.
Here's my current clearValidation code:
public function clearSpreadsheetValidations($spreadsheetId) {
$client = $this->getClient();
$service = new Google_Service_Sheets($client);
$conditions = new Google_Service_Sheets_BooleanCondition();
$conditions->setType('CONDITION_TYPE_UNSPECIFIED');
$conditions->setValues(null);
$setRule= new Google_Service_Sheets_DataValidationRule();
$setRule->setCondition($conditions);
$setRule->setInputMessage(null);
$setRule->setShowCustomUi(false);
$valReq = new Google_Service_Sheets_SetDataValidationRequest();
$valReq->setRule($setRule);
$sheetReq = new Google_Service_Sheets_Request();
$sheetReq->setSetDataValidation($valReq);
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$requestBody->setRequests($sheetReq);
$service->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
}
How can I call the sheets API to remove all previously set DataValidationRules in a spreadsheet?
Thanks!
Okay, as noted here
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request
SetDataValidationRequest
Sets a data validation rule to every cell in the range. To clear
validation in a range, call this with no rule specified.
So all I had to do, was simply not declare a range, or set a rule, and ran this method on the existing spreadsheet to clear all existing validations
public function clearSpreadsheetValidations($spreadsheetId) {
$client = $this->getSheetsClient();
$service = new Google_Service_Sheets($client);
$valReq = new Google_Service_Sheets_SetDataValidationRequest();
$sheetReq = new Google_Service_Sheets_Request();
$sheetReq->setSetDataValidation($valReq);
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$requestBody->setRequests($sheetReq);
$service->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
}
For java this code worked in my case.
public BatchUpdateSpreadsheetResponse removeAllDataValidation(String spreadsheetId, Sheets service)
throws IOException {
// [START sheets_conditional_formatting]
List<Request> requests = Arrays.asList(new Request().setSetDataValidation(
new SetDataValidationRequest()));
BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest().setRequests(requests);
BatchUpdateSpreadsheetResponse result = service.spreadsheets().batchUpdate(spreadsheetId, body).execute();
System.out.printf("%d cells updated.", result.getReplies().size());
// [END sheets_conditional_formatting]
return result;
}
I am using Docusign PHP Client and trying to create and envelope and send it as email. With the current SDK, I was getting an error:
INVALID_REQUEST_BODY The request body is missing or improperly formatted. Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'API_REST.Models.v2.document[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\n ◀
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive t ▶
Path 'documents.documentBase64', line 1, position 31.
So I had to edit EnvelopeApi.php (line 2876) json_encode($httpBody) to make it work.
Now that it's working, I receive a response like this, however I can't change status created to sent is my problem.
EnvelopeSummary {#460 ▼
#container: array:4 [▼
"envelope_id" => "6b9ef863-2ee0-4ea6-9f7e-20b7d4f59b22"
"status" => "created"
"status_date_time" => "2018-10-03T12:30:22.8600000Z"
"uri" => "/envelopes/6b9ef863-2ee0-4ea6-9f7e-20b7d4f59b22"
]
}
My full code:
First, I authenticated and fetched my $accountId
And then creating Envelope:
$path = public_path('test.pdf');
$b64Doc = base64_encode(file_get_contents($path));
$document = new Document();
$document->setName("TEST.pdf");
$document->setFileExtension("pdf");
$document->setDocumentId(1);
$document->setDocumentBase64($b64Doc);
$sign_here = new SignHere();
$sign_here->setXPosition(25);
$sign_here->setYPosition(50);
$sign_here->setDocumentId(1);
$sign_here->setPageNumber(1);
$sign_here->setRecipientId(1);
$tabs = new Tabs();
$tabs->setSignHereTabs($sign_here);
$signers = new Signer();
$signers->setName('Test User');
$signers->setEmail('test#mailinator.com');
$signers->setRoleName('Signer');
$signers->setRecipientId(1);
$signers->setRoutingOrder(1);
$signers->setTabs($tabs);
$recipients = new Recipients();
$recipients->setSigners($signers);
$envelope_definition = new EnvelopeDefinition();
$envelope_definition->setEmailSubject('Signature Request');
$envelope_definition->setStatus("sent"); // ***
$envelope_definition->setDocuments($document);
$envelope_definition->setRecipients($recipients);
$options = new CreateEnvelopeOptions();
$options->setCdseMode(null);
$options->setMergeRolesOnDraft(null);
try {
$envelopeSummary = $envelopeApi->createEnvelope($accountId, $envelope_definition, $options);
dd($envelopeSummary);
// Also tried this:
// $envelopeApi->update($accountId, $envelopeSummary->getEnvelopeId(), json_encode(['status' => 'sent']);
} catch (ApiException $e){
dd($e->getResponseBody()->errorCode . " " . $e->getResponseBody()->message);
}
$envelope_definition->setStatus("sent"); this should trigger the email, right? But it doesn't for some reason. Also I can't see this created envelope in my Sandbox either.
You are not setting signers correctly. It must be an array of signer objects.
Here is some untested code:
# This code creates a signer, not signers
$signer = new Signer();
$signer->setName('Test User');
$signer->setEmail('test#mailinator.com');
$signer->setRoleName('Signer');
$signer->setRecipientId(1);
$signer->setRoutingOrder(1);
$signer->setTabs($tabs);
$recipients = new Recipients();
# setSigners wants an array of signer objects.
# in this case, we make an array with one element
$recipients->setSigners(array($signer));
Also, you are not creating the tabs right either. Again, it needs to be an array of the tab type.
See this example for additional ideas.
Yes, setting status to sent should make DocuSign send the envelope upon creation. The fact that the response contains "status" => "created" seems to indicate that your setting of the property ($envelope_definition->setStatus("sent");) is not actually being included as part of the request that's being issued to DocuSign.
I've compared your code with the code examples provided in GitHub for the PHP SDK, specifically, with the signatureRequestOnDocument function on that page. The only obvious difference I can see between your code and that example code is in the syntax for creating objects. For example, creating the envelope:
Your code: $envelope_definition = new EnvelopeDefinition();
PHP SDK example code: $envelop_definition = new DocuSign\eSign\Model\EnvelopeDefinition();
I don't know much about PHP, let alone about the DocuSign PHP SDK, but I'd suggest that you try to closely mimic the code examples that are part of the SDK repo on GitHub, to see if you get a different result that way.
My code work like this :
$signersArray = array();
$signer = new Signer();
$signer->set...
$signersArray[] = $signer;
$recipients->setSigners($signersArray);
If it's not working try to dump the data send from the SDK to the API and double check that the status is correct :
Go to Docusign/esign-client/src/ApiClient.php and var_dump($postData) at line 159
I'm currently trying to obtain a list of the three most read articles on my site, using the Google Analytics Reporting API v4.
Currently, I have been able to request a list of all pages with the number of pageviews each one got in the past 30 days, and filter them by pageview.
But now I'm stuck (after browsing for answers for multiple hours) to filter so only pagepaths that include /artikels/ are shown, and limit the list to 3 results.
My current code:
function getReport($analytics) {
// Replace with your view ID, for example XXXX.
$VIEW_ID = "XXXXXXX";
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate("30daysAgo");
$dateRange->setEndDate("today");
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:pageviews");
$sessions->setAlias("sessions");
//Create the Dimensions object.
$pagepath = new Google_Service_AnalyticsReporting_Dimension();
$pagepath->setName("ga:pagePath");
$ordering = new Google_Service_AnalyticsReporting_OrderBy();
$ordering->setOrderType("VALUE");
$ordering->setFieldName("ga:pageviews");
$ordering->setSortOrder("DESCENDING");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setDimensions(array($pagepath));
$request->setOrderBys($ordering);
$request->setMetrics(array($sessions));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
}
Could anyone please help? There is a ton of information about v3, but can't seem to find enough information about v4.
Thank you!
Using the latest NetSuite PHP Toolkit v2012_2, how can I get the contents of lists and in particular custom lists?
For example, we have a custom list with options for how the customer heard about us. We modify this list from time to time. When a visitor to our site gets to our registration screen we’d like to pull in from NetSuite the list items for the custom list with id 3 (along with each list item’s id) so we can fill a drop-down box for use when creating a contact in NetSuite. This way we can maintain a single list in NetSuite and it will always be current in the website.
Credit and thanks to Saqib!
For reference, here is an example of the code that is now working:
$service = new NetSuiteService();
$service->setSearchPreferences(false, 20);
$recordRef = new RecordRef();
$recordRef->internalId = 1;
$searchField = new SearchMultiSelectField();
$searchField->operator = "anyOf";
$searchField->searchValue = $recordRef;
$search = new CustomListSearchBasic();
$search->internalId = $searchField;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
var_dump($searchResponse);
die();
Perhaps http://tellsaqib.github.com/NSPHP-Doc/ could help you in coding it yourself.