---
title: "Linking Google Analytics"
date: "2015-06-03"
category: "control-panel"
slug: "linking-google-analytics"
---

Hosting platforms [[determining-platform-version]] support integrating Google Analytics directly into the ApisCP Dashboard. This provides visitor counts, behavior tracking, SEO metrics, goal targeting, and browser usage data at a glance.

![Sample Dashboard with integrated Analytics](kb-image:dashboard-analytics.png)
*Sample Dashboard with integrated Analytics*

## Prerequisites

Google Analytics must be configured for your site before proceeding. See [[enabling-google-analytics-support]].

## Step 1: Configure Google API Credentials

1. Log in to the [Google Code API Console](https://code.google.com/apis/console)
2. Navigate to **APIs & Auth** > **Credentials**
3. Click **Create new Client ID**
    - If prompted, create a product on the consent screen:
      ![Prompt to create product ID on Consent screen](kb-image:google-code-consent.png)
    - Enter a project name and click **Save**:
      [![Create a project name](kb-image:google-code-consent-2.png)](kb-image:google-code-consent-2.png)
4. Select **Application type** > **Web application**
5. Under **Authorized JavaScript origins**, enter the origin shown in **Account** > **Settings** within the [[logging-into-the-control-panel]]. If an API key is already present, delete it to reveal the suggested origin.
    ![Suggested authorized origin in Account > Settings](kb-image:origin-suggestion.png)
    *Suggested authorized origin in Account > Settings*
    - Use `https://` unless you connect to the panel over `http://`
6. Click **Create ID**
    ![Configured Client ID dialog generated for an account on the server named ](kb-image:create-client-id-modal.png)
    *Configured Client ID dialog generated for an account on the server named "Sol"*
7. Copy the **Client ID** value for use in the next section
    ![Sample client ID generated within Google's API console. Client ID masked for security.](kb-image:sample-client-id.png)
    *Sample client ID generated within Google's API console. Client ID masked for security.*
8. Navigate to **APIs & Auth** > **APIs**, search for "Analytics API", and select it
9. Click **Enable API** if not already enabled
    ![Enable API button to enable Analytics data sharing within the control panel.](kb-image:enable-api-button.png)
    *Enable API button to enable Analytics data sharing within the control panel.*

## Step 2: Configure the Control Panel

1. Visit **Account** > **Settings** and paste the **Client ID** into **Google Analytics API Key**
2. Click **Save Changes**
3. Visit **Web** > **.htaccess Manager** (this can also be done via the [[htaccess-guide]] directive ModPagespeedAnalyticsID)
4. Click the Edit action for the domain or subdomain to configure
5. Click **Add Directive** and set **Personality** to `Pagespeed`
6. Add the Analytics ID directive:
    - **Directive:** `ModPagespeedAnalyticsID`
    - **Value:** Your Analytics ID from [[enabling-google-analytics-support]]
    - Click **Add**
      ![Sample input configuring your Analytics ID.](kb-image:sample-personality-input.png)
      *Sample input configuring your Analytics ID.*
7. Add the Analytics injection filter:
    - **Directive:** `ModPageSpeedEnableFilters`
    - **Value:** `insert_ga`
    - Click **Add**
8. Click **Save Changes** to save the .htaccess file
9. Return to **Account** > **Dashboard** and click **Access Google Analytics** to authenticate
    ![Access Google Analytics button to sign-on and begin sharing data with the control panel.](kb-image:access-google-analytics-button.png)
    *Access Google Analytics button to sign-on and begin sharing data with the control panel.*
    - If you receive an "Error: origin_mismatch" message, the **Authorized JavaScript origins** is incorrect. Fix it in the Google API Console. Changes may take up to 15 minutes to propagate.
10. Refresh the page to load statistics
    - If statistics do not load, verify that the Analytics API is enabled in Google's API Console

## Disabling Analytics

Navigate to **Account** > **Settings** > Control Panel > **Google Analytics API Key** > **Delete** to remove the API key and disable integrated Analytics.

## Limitations

Analytics only tracks well-formed HTML pages. Direct file downloads (e.g., images, ZIP files accessed via direct URL) are not reflected in Analytics data because the tracking JavaScript can only be injected into HTML documents. However, images and other assets loaded inline within an HTML page are tracked normally.
