简体   繁体   中英

Creating Google Analytics Dashboard With Custom Dates

I am creating a dashboard using Google Analytics Data using JSON webservice. What it does is when I enter the From Date & To Date, Google analytics will trigger a query according to that dates and reply with a response.

According to that response the chart will be drawn.

Updated

Two dates taken from a HTML form & it's in below.

Dashboard.html

<script type="text\javascript src="js/jquerysoap.js"></script>
<script type="text/javascript" src="js/script.js"></script>

</head>
<form action="" method="post">
    From Date : <input type="text" id="from_date" />
    To Date : <input type="text" id="to_date" />
    <input type="submit" value="Submit" class="submit_button" onClick="getVaria(); return false" />
    </form>

These entered dates will be grabbed by some JavaScript functions in the Script.js file.

Script.js

function retStartDate(){

var strStartDate = document.getElementById("from_date").value;

alert("Start date " + strStartDate);

return strStartDate;

}

function retEndDate(){

var strEndDate = document.getElementById("to_date").value;

alert("End date " + strEndDate);

return strEndDate;

}

These 2 dates will then paaased to the chart query to fraw the chart as like the below.

function getVaria(){

/* Chart query.*/

var strWsUrl = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&  dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource!%3D(direct)&sort=-ga%3Ausers&start-date= ' + retStartDate() + ' &end-date= ' + retEndDate() + ' &max-results=10';

alert(strWsUrl);

return strWsUrl;

}    

The source code is above.

I am able to pass the 2 dates to the query. Then I cannot find out a way to get the response from JSON and so on. I'm using JavaScript on this one because it gives more mobility than server side scripting. So could you someone give me a clue for that?

Thanks & regards, Chiranthaka

This error is generated because I used the 'return' value instead of the JavaScript Function() name. The correct one is at the below.

var strWsUrl =

' https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions= '+ 'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date='+retStartDate()+'&end-date='+retEndDate()+'&max-results=10';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM