Read Custom variable's data using google analytics api c# -
i'm trying use google analytics api c# retrieve custom varaibles's google analytics. try http://www.c-sharpcorner.com/uploadfile/f9f215/how-to-fetch-google-analytics-statistics-and-display-it-in-y , can read custom dimension data, want read custom variable's data, return null. code given below :
// path of .p12 file string keyfilepath = system.web.httpcontext.current.server.mappath("path/of/my/.p12"); string serviceaccountemail = "xxx-xxxxx@developer.gserviceaccount.com"; string websitecode = "xxxxxxxxx"; string keypassword = "notasecret"; analyticsservice service = null; var scopes = new string[] { analyticsservice.scope.analytics, // view , manage analytics data analyticsservice.scope.analyticsedit, // edit management actives analyticsservice.scope.analyticsmanageusers, // manage users analyticsservice.scope.analyticsreadonly}; // view analytics data var credential = new serviceaccountcredential(new serviceaccountcredential.initializer(serviceaccountemail) { scopes = scopes }.fromcertificate(certificate)); service = new analyticsservice(new baseclientservice.initializer() { httpclientinitializer = credential }); dataresource.garesource.getrequest request = service.data.ga.get( "ga:" + websitecode, datetime.today.adddays(-15).tostring("yyyy-mm-dd"), datetime.today.tostring("yyyy-mm-dd"), "ga:sessions,ga:users"); request.dimensions = "ga:dimension1"; // possible add custom variable here // return exception bcz no such dimension named: "customvar1" // request.dimensions = "ga:customvar1"; var data = request.execute(); // data.row null thanks in advance.
in request.dimensions = "ga:dimension1"; use dimentoin, not custom variable. change line following code
request.dimensions = "ga:customvarname1"; // or can use request.dimensions = "ga:customvarvalue1"; for more custom variable read google custom variable reference , retrieve custom variable read https://developers.google.com/analytics/devguides/reporting/core/dimsmets#view=detail&group=custom_variables_or_columns, hope problem solved.
Comments
Post a Comment