I have the following URL assigned to a variable in a webpage using JavaScript. The code snippet is below.
googleURL = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions='+'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=2014-04-05&end-date=2014-04-23&max-results=10';
The startdate & enddate values are static. Now I want that perticualr dates to be dynamic & the dates will be get from a HTML form & I already have that done. Those values are assigned into 2 different JS variables already. But I add those variables to the URL as below.
googleURL = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions='+'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=strStartDate&end-date=strEndDate&max-results=10';
Please look at start-date and end-date, there you can find the JS variable names that I have replaced with static dates.
When I alterted the edited googleURL, it displays as at the below.
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=strStartDate&end-date=strEndDate&max-results=10
I think the variable values are not assigning to or replacing the specified variables. The code snippet I'm working is at the below.
var strStartDate;
var strEndDate;
var googleURL;
function passVariable() {
strStartDate = document.getElementById("from_date").value;
strEndDate = document.getElementById("to_date").value;
alert(strStartDate);
alert(strEndDate);
document.write(googleURL);
}
googleURL = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions='+'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=strStartDate&end-date=strEndDate&max-results=10';
passVariable();
I'm using JavaScript. could someone helpme to solve this matter?
Thanks & regards,
Chiranthaka