I am trying to embed Google Trends graphs on pages of a Wordpress site, using the embed code provided by Google Trends themselves, for instance:
<script type="text/javascript" src="https://ssl.gstatic.com/trends_nrtr/1709_RC01/embed_loader.js"></script> <script type="text/javascript"> trends.embed.renderExploreWidget("TIMESERIES", {"comparisonItem":[{"keyword":"sample word","geo":"","time":"2004-01-01 2019-02-24"}],"category":0,"property":""}, {"exploreQuery":"date=all&q=sample%20word","guestPath":"https://trends.google.com:443/trends/embed/"}); </script>
The problem is that, as mentioned in the embed modal:
This data is static and will not update
However, it looks like that problem could be solved by updating the end date defined in the embed code for the time
parameter to the value of the current date, thus making sure the graph is always up to date:
"time":"2004-01-01 2019-02-24"
Where today's date
would replace 2019-02-24
above.
Can this be done with a simple var date = today.getDate();
? If yes, what is the cleanest way to include that in the embed code?