How to Embed Google Trends into React app





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm attempting to embed Google Trends into React so I can adjust the parameters dynamically. I can successfully embed it directly into the index.html file.



   <script
type="text/javascript"
src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
></script>
<script type="text/javascript">
trends.embed.renderExploreWidget(
"TIMESERIES",
{
comparisonItem: [{ keyword: "/m/030q7", geo: "", time: "now 7-d" }],
category: 0,
property: ""
},
{
exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
guestPath: "https://trends.google.com:443/trends/embed/"
}
);
</script>


However, I need to be able to change it via user input, so it needs to be in my jsx file. I've found a useful Helmet component to assist in adding scripts



  <Helmet>
<script
type="text/javascript"
src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
/>
<script type="text/javascript">
{trends.embed.renderExploreWidget(
"TIMESERIES",
{
comparisonItem: [
{ keyword: "/m/030q7", geo: "", time: "now 7-d" }
],
category: 0,
property: ""
},
{
exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
guestPath: "https://trends.google.com:443/trends/embed/"
}
)}
</script>
</Helmet>


but I'm getting such as




'trends' is not defined no-undef




I've tried adding 'this' and 'window' but get different errors.



Can anyone assist in helping me fix this?



EDIT



Although the proposed solution didn't work for me directly, I did manage to get it working properly by taking the generated iframe tag and implement this instead.



          <iframe
id="trends-widget-2"
src="https://trends.google.com:443/trends/embed/explore/TIMESERIES?req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22bitcoin%22%2C%22geo%22%3A%22US%22%2C%22time%22%3A%22today%2012-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D&amp;tz=-480&amp;eq=q%3Dbrexit%26geo%3DUS%26date%3Dtoday%2012-m"
width="100%"
height="300px"
frameborder="0"
scrolling="0"
/>









share|improve this question































    0















    I'm attempting to embed Google Trends into React so I can adjust the parameters dynamically. I can successfully embed it directly into the index.html file.



       <script
    type="text/javascript"
    src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
    ></script>
    <script type="text/javascript">
    trends.embed.renderExploreWidget(
    "TIMESERIES",
    {
    comparisonItem: [{ keyword: "/m/030q7", geo: "", time: "now 7-d" }],
    category: 0,
    property: ""
    },
    {
    exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
    guestPath: "https://trends.google.com:443/trends/embed/"
    }
    );
    </script>


    However, I need to be able to change it via user input, so it needs to be in my jsx file. I've found a useful Helmet component to assist in adding scripts



      <Helmet>
    <script
    type="text/javascript"
    src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
    />
    <script type="text/javascript">
    {trends.embed.renderExploreWidget(
    "TIMESERIES",
    {
    comparisonItem: [
    { keyword: "/m/030q7", geo: "", time: "now 7-d" }
    ],
    category: 0,
    property: ""
    },
    {
    exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
    guestPath: "https://trends.google.com:443/trends/embed/"
    }
    )}
    </script>
    </Helmet>


    but I'm getting such as




    'trends' is not defined no-undef




    I've tried adding 'this' and 'window' but get different errors.



    Can anyone assist in helping me fix this?



    EDIT



    Although the proposed solution didn't work for me directly, I did manage to get it working properly by taking the generated iframe tag and implement this instead.



              <iframe
    id="trends-widget-2"
    src="https://trends.google.com:443/trends/embed/explore/TIMESERIES?req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22bitcoin%22%2C%22geo%22%3A%22US%22%2C%22time%22%3A%22today%2012-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D&amp;tz=-480&amp;eq=q%3Dbrexit%26geo%3DUS%26date%3Dtoday%2012-m"
    width="100%"
    height="300px"
    frameborder="0"
    scrolling="0"
    />









    share|improve this question



























      0












      0








      0








      I'm attempting to embed Google Trends into React so I can adjust the parameters dynamically. I can successfully embed it directly into the index.html file.



         <script
      type="text/javascript"
      src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
      ></script>
      <script type="text/javascript">
      trends.embed.renderExploreWidget(
      "TIMESERIES",
      {
      comparisonItem: [{ keyword: "/m/030q7", geo: "", time: "now 7-d" }],
      category: 0,
      property: ""
      },
      {
      exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
      guestPath: "https://trends.google.com:443/trends/embed/"
      }
      );
      </script>


      However, I need to be able to change it via user input, so it needs to be in my jsx file. I've found a useful Helmet component to assist in adding scripts



        <Helmet>
      <script
      type="text/javascript"
      src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
      />
      <script type="text/javascript">
      {trends.embed.renderExploreWidget(
      "TIMESERIES",
      {
      comparisonItem: [
      { keyword: "/m/030q7", geo: "", time: "now 7-d" }
      ],
      category: 0,
      property: ""
      },
      {
      exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
      guestPath: "https://trends.google.com:443/trends/embed/"
      }
      )}
      </script>
      </Helmet>


      but I'm getting such as




      'trends' is not defined no-undef




      I've tried adding 'this' and 'window' but get different errors.



      Can anyone assist in helping me fix this?



      EDIT



      Although the proposed solution didn't work for me directly, I did manage to get it working properly by taking the generated iframe tag and implement this instead.



                <iframe
      id="trends-widget-2"
      src="https://trends.google.com:443/trends/embed/explore/TIMESERIES?req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22bitcoin%22%2C%22geo%22%3A%22US%22%2C%22time%22%3A%22today%2012-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D&amp;tz=-480&amp;eq=q%3Dbrexit%26geo%3DUS%26date%3Dtoday%2012-m"
      width="100%"
      height="300px"
      frameborder="0"
      scrolling="0"
      />









      share|improve this question
















      I'm attempting to embed Google Trends into React so I can adjust the parameters dynamically. I can successfully embed it directly into the index.html file.



         <script
      type="text/javascript"
      src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
      ></script>
      <script type="text/javascript">
      trends.embed.renderExploreWidget(
      "TIMESERIES",
      {
      comparisonItem: [{ keyword: "/m/030q7", geo: "", time: "now 7-d" }],
      category: 0,
      property: ""
      },
      {
      exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
      guestPath: "https://trends.google.com:443/trends/embed/"
      }
      );
      </script>


      However, I need to be able to change it via user input, so it needs to be in my jsx file. I've found a useful Helmet component to assist in adding scripts



        <Helmet>
      <script
      type="text/javascript"
      src="https://ssl.gstatic.com/trends_nrtr/1644_RC01/embed_loader.js"
      />
      <script type="text/javascript">
      {trends.embed.renderExploreWidget(
      "TIMESERIES",
      {
      comparisonItem: [
      { keyword: "/m/030q7", geo: "", time: "now 7-d" }
      ],
      category: 0,
      property: ""
      },
      {
      exploreQuery: "q=%2Fm%2F030q7&date=now%207-d",
      guestPath: "https://trends.google.com:443/trends/embed/"
      }
      )}
      </script>
      </Helmet>


      but I'm getting such as




      'trends' is not defined no-undef




      I've tried adding 'this' and 'window' but get different errors.



      Can anyone assist in helping me fix this?



      EDIT



      Although the proposed solution didn't work for me directly, I did manage to get it working properly by taking the generated iframe tag and implement this instead.



                <iframe
      id="trends-widget-2"
      src="https://trends.google.com:443/trends/embed/explore/TIMESERIES?req=%7B%22comparisonItem%22%3A%5B%7B%22keyword%22%3A%22bitcoin%22%2C%22geo%22%3A%22US%22%2C%22time%22%3A%22today%2012-m%22%7D%5D%2C%22category%22%3A0%2C%22property%22%3A%22%22%7D&amp;tz=-480&amp;eq=q%3Dbrexit%26geo%3DUS%26date%3Dtoday%2012-m"
      width="100%"
      height="300px"
      frameborder="0"
      scrolling="0"
      />






      reactjs embed google-trends






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 12 at 5:24







      RRM1000

















      asked Nov 24 '18 at 9:15









      RRM1000RRM1000

      427




      427
























          1 Answer
          1






          active

          oldest

          votes


















          1














          First load the script url on your html file. Then use react-script-tag from npm and then write this on your component's render:



          <ScriptTag type="text/javascript">
          {'trends.embed.renderExploreWidgetTo(
          document.getElementById('widget'),
          'TIMESERIES',
          {'comparisonItem': [{'keyword':'chicken','geo':'','time':'today 12-m'}],'category':0,'property':''},
          {'exploreQuery':'q=chicken&date=today 12-m','guestPath':'https://trends.google.com:443/trends/embed/'}
          )'}
          </ScriptTag>





          share|improve this answer


























          • When I added this, it still didn't display properly (took entire page) but I was able to take the generated iframe and use this instead (see edited question). Thanks for your help!

            – RRM1000
            Mar 12 at 5:26













          • No problem, we also had this problem and glad to helped you brother!

            – Dynn Tolentino
            Apr 10 at 14:25












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456764%2fhow-to-embed-google-trends-into-react-app%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          First load the script url on your html file. Then use react-script-tag from npm and then write this on your component's render:



          <ScriptTag type="text/javascript">
          {'trends.embed.renderExploreWidgetTo(
          document.getElementById('widget'),
          'TIMESERIES',
          {'comparisonItem': [{'keyword':'chicken','geo':'','time':'today 12-m'}],'category':0,'property':''},
          {'exploreQuery':'q=chicken&date=today 12-m','guestPath':'https://trends.google.com:443/trends/embed/'}
          )'}
          </ScriptTag>





          share|improve this answer


























          • When I added this, it still didn't display properly (took entire page) but I was able to take the generated iframe and use this instead (see edited question). Thanks for your help!

            – RRM1000
            Mar 12 at 5:26













          • No problem, we also had this problem and glad to helped you brother!

            – Dynn Tolentino
            Apr 10 at 14:25
















          1














          First load the script url on your html file. Then use react-script-tag from npm and then write this on your component's render:



          <ScriptTag type="text/javascript">
          {'trends.embed.renderExploreWidgetTo(
          document.getElementById('widget'),
          'TIMESERIES',
          {'comparisonItem': [{'keyword':'chicken','geo':'','time':'today 12-m'}],'category':0,'property':''},
          {'exploreQuery':'q=chicken&date=today 12-m','guestPath':'https://trends.google.com:443/trends/embed/'}
          )'}
          </ScriptTag>





          share|improve this answer


























          • When I added this, it still didn't display properly (took entire page) but I was able to take the generated iframe and use this instead (see edited question). Thanks for your help!

            – RRM1000
            Mar 12 at 5:26













          • No problem, we also had this problem and glad to helped you brother!

            – Dynn Tolentino
            Apr 10 at 14:25














          1












          1








          1







          First load the script url on your html file. Then use react-script-tag from npm and then write this on your component's render:



          <ScriptTag type="text/javascript">
          {'trends.embed.renderExploreWidgetTo(
          document.getElementById('widget'),
          'TIMESERIES',
          {'comparisonItem': [{'keyword':'chicken','geo':'','time':'today 12-m'}],'category':0,'property':''},
          {'exploreQuery':'q=chicken&date=today 12-m','guestPath':'https://trends.google.com:443/trends/embed/'}
          )'}
          </ScriptTag>





          share|improve this answer















          First load the script url on your html file. Then use react-script-tag from npm and then write this on your component's render:



          <ScriptTag type="text/javascript">
          {'trends.embed.renderExploreWidgetTo(
          document.getElementById('widget'),
          'TIMESERIES',
          {'comparisonItem': [{'keyword':'chicken','geo':'','time':'today 12-m'}],'category':0,'property':''},
          {'exploreQuery':'q=chicken&date=today 12-m','guestPath':'https://trends.google.com:443/trends/embed/'}
          )'}
          </ScriptTag>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 10 at 9:47

























          answered Mar 10 at 4:51









          Dynn TolentinoDynn Tolentino

          264




          264













          • When I added this, it still didn't display properly (took entire page) but I was able to take the generated iframe and use this instead (see edited question). Thanks for your help!

            – RRM1000
            Mar 12 at 5:26













          • No problem, we also had this problem and glad to helped you brother!

            – Dynn Tolentino
            Apr 10 at 14:25



















          • When I added this, it still didn't display properly (took entire page) but I was able to take the generated iframe and use this instead (see edited question). Thanks for your help!

            – RRM1000
            Mar 12 at 5:26













          • No problem, we also had this problem and glad to helped you brother!

            – Dynn Tolentino
            Apr 10 at 14:25

















          When I added this, it still didn't display properly (took entire page) but I was able to take the generated iframe and use this instead (see edited question). Thanks for your help!

          – RRM1000
          Mar 12 at 5:26







          When I added this, it still didn't display properly (took entire page) but I was able to take the generated iframe and use this instead (see edited question). Thanks for your help!

          – RRM1000
          Mar 12 at 5:26















          No problem, we also had this problem and glad to helped you brother!

          – Dynn Tolentino
          Apr 10 at 14:25





          No problem, we also had this problem and glad to helped you brother!

          – Dynn Tolentino
          Apr 10 at 14:25




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456764%2fhow-to-embed-google-trends-into-react-app%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()