I am trying to apply a segment for a query through Google Analytics .NET client but I am not able to get it working. Here is what I have been trying:
var segments = analyticsService.Management.Segments.List().Execute();
var engagedTeamsSegment = segments.Items.FirstOrDefault(x => x.Name.Equals("Engaged Teams", StringComparison.OrdinalIgnoreCase));
var format = "yyyy-MM-dd";
var today = DateTime.UtcNow.Date;
var thirtyDaysAgo = today.Subtract(TimeSpan.FromDays(30));
var metrics = engagedTeamsSegment.Definition.Replace(';', ',');
var gaData = analyticsService
.Data.Ga
.Get($"ga:{profile.Id}", today.ToString(format), thirtyDaysAgo.ToString(format), metrics)
.Execute();
It's getting me the below error
An unhandled exception of type 'Google.GoogleApiException' occurred in
Google.Apis.dll
Additional information: Google.Apis.Requests.RequestError
Invalid value
'users::condition::ga:dimension2!=0,ga:sessionCount>=2,ga:daysSinceLastSession<=14'.
Values must match the following regular expression: 'ga:.+' [400]
Errors [
Message[Invalid value
'users::condition::ga:dimension2!=0,ga:sessionCount>=2,ga:daysSinceLastSession<=14'.
Values must match the following regular expression: 'ga:.+']
Location[metrics - parameter] Reason[invalidParameter] Domain[global]
]
I am probably doing something wrong but not sure what. Any ideas?
Found the solution thanks to this question. There was a Segment parameter on the request. Below code did the trick:
var segments = analyticsService.Management.Segments.List().Execute();
var engagedTeamsSegment = segments.Items.FirstOrDefault(x => x.Name.Equals("Engaged Teams", StringComparison.OrdinalIgnoreCase));
var format = "yyyy-MM-dd";
var today = DateTime.UtcNow.Date;
var thirtyDaysAgo = today.Subtract(TimeSpan.FromDays(30));
var gaDataRequest = analyticsService
.Data.Ga
.Get($"ga:{profile.Id}", thirtyDaysAgo.ToString(format), today.ToString(format), "ga:users");
gaDataRequest.Segment = engagedTeamsSegment.Definition;
var gaData = gaDataRequest.Execute();
Related
I want to filter time series in the google earth engine which requires two for loops over time-series of a single pixel. I searched around and not found any example related to this. I know about .map function and I am using it for the generation of RVI on the earth engine. I found about .toArray function but not found any example related to my problem.
I will appreciate any help in this regard. Also, I am new to the earth engine so this may be a trivial question for others.
This is the code that I have. I took it from a blog and modified it according to my need. I am stuck after this.
var sentinel1 = ee.ImageCollection('COPERNICUS/S1_GRD_FLOAT');
// Filter VH, IW
var vh = sentinel1
// Filter to get images with VV and VH dual polarization.
//.filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
// Filter to get images collected in interferometric wide swath mode.
.filter(ee.Filter.eq('instrumentMode', 'IW'))
// reduce to VH polarization
//.select('VH')
// filter 10m resolution
.filter(ee.Filter.eq('resolution_meters', 10));
// Filter to orbitdirection Descending
var vhDescending = vh.filter(ee.Filter.eq('orbitProperties_pass', 'DESCENDING'));
// Filter time 2015
var vhDesc2015 = vhDescending.filterDate(ee.Date('2021-01-01'), ee.Date('2021-04-30'));
// Filter to MKD roi
var s1_mkd = vhDesc2015.filterBounds(roi);
print('All metadata:', s1_mkd);
var count = s1_mkd.size();
print('Count: ', count);
//var dates = s1_mkd.aggregate_array("system:time_start")
//print('dates: ', dates);
var dates = s1_mkd
.map(function(image) {
return ee.Feature(null, {'date': image.date().format('YYYY-MM-dd')})
})
.distinct('date')
.aggregate_array('date')
print('dates: ', dates);
var featureCollection = ee.FeatureCollection(dates
.map(function(element){
return ee.Feature(null,{prop:element})}))
//Export a .csv table of date, mean NDVI for watershed
Export.table.toDrive({
collection: featureCollection,
description: 'Timeseries',
folder: 'WC_raw',
fileFormat: 'CSV',
});
var rvi4s1 = function(img){
var vh = img.select('VH');
var vv = img.select('VV');
var col = vv.divide(vv.add(vh)).sqrt().rename('dop');
var dop = col.select('dop')
var value = dop.multiply(vh.multiply(4).divide(vv.add(vh))).rename('rvi4s1');
return value;
};
var rvi = s1_mkd.map(rvi4s1);
print(rvi);
I'm trying to get audienc name aduience id etc we' ve created on our google analytics account. We have around 2,4k audiences list but I can just get 999 of them. I can't find any soultions. Code is below
function main() {
var spreadsheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadshe');
var sheet = spreadsheet.getSheetByName('Sh');
function listRemarketingAudiences(accountId, propertyId) {
var request = Analytics.Management.RemarketingAudience.list(
accountId,
propertyId
);
var leno = Object.keys(request).length
console.log(leno);
sheet.getRange(1,1).setValue("audianceName");
sheet.getRange(1,2).setValue("audianceId");
sheet.getRange(1,3).setValue("audianceDefinition");
sheet.getRange(1,4).setValue("audianceDescription");
for ( var i = 2; i <3000; i++) {
var audianceName = request.items[i+154].name ;
Logger.log(audianceName);
console.log(i);
sheet.getRange(i,1).setValue("elo")
var audianceId = request.items[i].id ;
sheet.getRange(i,2).setValue(audianceId);
// var audianceId = request.items[i].
var audienceDefinition = request.items[i].audienceDefinition ;
sheet.getRange(i,3).setValue(audienceDefinition);
var audienceDescription = request.items[i].description ;
sheet.getRange(i,4).setValue(audienceDescription);
};
}
listRemarketingAudiences('xxxxx', 'UA-xxxxx-1');
}
Currently you are supplying only the required parameters: accountId and webPropertyId. These are necessary to identify the Analytics property, where you are looking for the data.
Based on the documentation, optional parameters can be passed, which are actually in connection with the pagination, which you are trying to achieve.
As the developer guide is not mentioning the absolute limit of the result, you could experiment with higher limits, with a code something like this:
request = gapi.client.analytics.management.remarketingAudience.list(
{
'accountId': accountId,
'webPropertyId': propertyId,
'max-results': 5000
}
If you can't get all the data at once, you need to implement paging yourself, where an other paramerer, start-index will be necessary. You need to call the function several times, preferably from a loop, where start index is continuously increased.
request = gapi.client.analytics.management.remarketingAudience.list(
{
'accountId': accountId,
'webPropertyId': propertyId,
'start-index': 999,
'max-results': 1000
}
I wrote sth like this:
var optional = {'startIndex': 12,
'maxresults': 212};
function listRemarketingAudiences (accountId, propertyId, optional){
var request = Analytics.Management.RemarketingAudience.list(
accountId,
propertyId,
optional.maxresults
);
and an error occure:
We're sorry, a server error occurred. Please wait a bit and try again. (line 9, file "Code")
I have created one form in that am getting data only header parts but m not getting data from subsist record please help me. I have used so many APIs but trying to get stored record type.
From testing, the sublist structure in POST data is stored in the request parameters:
var sublistId = 'insertsublistid';
var valuesParam = sublistId + 'data';
var fieldsParam = sublistId + 'fields';
The data are delimited by the following characters:
var SUBLIST_FIELD_DELIM = /\u0001/;
var SUBLIST_LINE_DELIM = /\u0002/;
This is for SS 2.0
var value = context.request.getSublistValue({
group: 'item',
name: 'amount',
line: '2'
});
See /app/help/helpcenter.nl?fid=section_4314828231.html
I can take the results of my variable xmlDoc and save it to an xml document (on disk) and the query returns results; however, when I run it live (with the code below) the query results are null.
Why is my query not working against the xmlDoc?? See screen shot below for the debug output 'xmlDoc.Root'.
There must be a cleaner way to create the XDocument??
System.Net.WebClient wc = new System.Net.WebClient();
wc.Credentials = new System.Net.NetworkCredential("bagee18#gmail.com", "my_password");
XDocument xmlDoc = XDocument.Parse(wc.DownloadString(new Uri("https://mail.google.com/mail/feed/atom")), LoadOptions.None);
var q = (from c in xmlDoc.Descendants("entry")
select new
{
name = c.Element("title").Value,
url = c.Element("link").Attribute("href").Value,
email = c.Element("author").Element("email").Value
}).ToList();
q.Dump();
xmlDoc.Root:
.
Take the namespace into account:
XNamespace df = xmlDoc.Root.Name.Namespace;
var q = (from c in xmlDoc.Descendants(df + "entry")
select new
{
name = c.Element(df + "title").Value,
url = c.Element(df + "link").Attribute("href").Value,
email = c.Element(df + "author").Element(df + "email").Value
}).ToList();
I want to add a label in flex to display m/s2 (read meters per second square). I would need to use superscripting for this.
I have tried out the following code which is giving me a compilation error.
var richtxt1:RichText = new RichText();
richtxt1.text="m/s";
var richtxt2:RichText = new RichText();
var span:SpanElement = new SpanElement();
span.text = "2";
span.baselineShift = "superscript";
richtxt2.addChild(span);
richtxt1.text=rixhtxt1.txt + richtxt2.text
I am getting a compilation error for the line richtxt2.addChild(span)
The error is
Implicit coercion of a value of type flashX.textLayout.elements.SpanElement
to unrelated type flash.Display.DisplayObject
I think you've to do something like this
var xmlText:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>" +
"m/s <span baselineShift='superscript'>2</span>" +
"</TextFlow>";
var txtFlow:TextFlow = TextFlowUtil.importFromXML(xmlText);
var richTxt:RichText = new RichText();
richtxt.textFlow = txtFlow;
I've not tested it so please excuse me of any compilation errors.
This is the code I used in my iPad app to accomplish the above:
var xmlText:String = "m/s <span baselineShift='superscript'>2</span>";
var txtFlow:TextFlow = TextFlowUtil.importFromString(xmlText);
var richTxt:RichText = new RichText();
richTxt.textFlow = txtFlow;
this.addElement(richTxt);
It is based on kaychaks and information I found from Adobe's website. The differences are
I took out the TextFlow markup but left in the HTML;
importFromString rather than importFromXML; and
I added this.addElement(richText) to display the element.