title: How to pass URL parameters across all pages/internal links in a site with javascript?
body: <p>I have a site with two pages, <code>index.html</code> and <code>page2.html</code>:</p>
  
  <p>index.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Homepage&lt;/title&gt;    
      &lt;style type="text/css"&gt;
        #holder {margin: 20px auto; max-width: 900px;}      
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="holder"&gt;
        &lt;h1&gt;Home&lt;/h1&gt;
        &lt;ul id="menu"&gt;
          &lt;li&gt;&lt;a href="/page2.html"&gt;Internal Link&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="https://www.apple.com/" target="_blank"&gt;App Store&lt;/a&gt; 
     &lt;/li&gt;
        &lt;/ul&gt;
        &lt;h2 id="useApp"&gt;Is the user using our app?&lt;/h2&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>page2.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Page 2&lt;/title&gt;    
      &lt;style type="text/css"&gt;
        #holder {margin: 20px auto; max-width: 900px;}      
      &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="holder"&gt;
        &lt;h1&gt;Internal Page&lt;/h1&gt;
        &lt;ul id="menu"&gt;
          &lt;li&gt;&lt;a href="/index.html"&gt;Homepage&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="https://www.apple.com/" target="_blank"&gt;App Store&lt;/a&gt; 
         &lt;/li&gt;
        &lt;/ul&gt;
        &lt;h2 id="useApp"&gt;Is the user using our app?&lt;/h2&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When the user lands on index.html by clicking a Google ad, in order to enable tracking the ad appends the following parameters to the end of the URL:  </p>
  
  <p><code>?utm_source=google&amp;utm_medium=search&amp;utm_campaign=summer19</code></p>
  
  <p>A problem that arises is when a user navigates to another page within the site, these URL parameters are lost.  I would like to write some Javascript that passes the URL parameters across the user's journey on the site when they click on internal links. In the case of external links, it MUST NOT include these parameters.  How can I implement this most effectively?</p>
  
  <p>All help is greatly appreciated.</p>