Ne Kr Ne Kr - 1 year ago 139
Javascript Question

redirect with javascript and analytics

I would like to know how I can track a link from an email with google analytics.

In the email there is a link to a pdf ebook confirmation page. In need to track that, so when a person click the link to the ebook, I need to take the URL parameters, and redirect with javascript to the confirmation page, after google analytics have registrered the tracking.

But how can I take the URL parameters and redirect with javascript? Is it something to do with


Answer Source

It would make sense to want this, if the destination URL was to a static PDF file that would be served directly by the HTTP server (no application involved). For example, Since the PDF is a static file, there is no way to inject the Google Analytics (GA) Javascript code to register the page view. To track the click in the email link using UTM codes and register the page view with GA, you would need an intermediate page that contains your GA javascript and pageView call and then use Javascript to redirect to the static PDF URL.

The code to this intermediate page would be something like this:

  <!-- Insert your Google Analytics code here; this must come first -->
  <script type="text/javascript">
    var ebook_url = "";
    window.location = ebook_url; // redirect happens here

Let's assume that intermediate redirect page is served at In the email you would add the UTM codes to that URL link, like @yuriy636 suggested:‌​m_medium=email&utm_c‌​ampaign=ebookdownloa‌​d

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download