Beispiel #1
0
/**
 * EXPERIMENTAL: Retrieve Google's visits for the given page
 * More work needs to be done. Needs caching, needs to be less resource intensive, and
 * needs an automated way to determine the page.
 * Function may/will change in future releases. Only use if you know what you're doing.
 *
 * @param url - the page url, missing the domain information
 * @param days - the number of days to get
 * @return the number of visits
 **/
function get_analytics_visits_by_page($page, $days = 31)
{
    require_once 'class.analytics.stats.php';
    # Create a new API object
    $api = new GoogleAnalyticsStats();
    # Get the current accounts accounts
    $accounts = ga_get_analytics_accounts();
    # Verify accounts exist
    if (count($accounts) <= 0) {
        return 0;
    }
    # Loop throught the account and return the current account
    foreach ($accounts as $account) {
        # Check if the UID matches the selected UID
        if ($account['ga:webPropertyId'] == get_option('ga_uid')) {
            $api->setAccount($account['id']);
            break;
        }
    }
    # Encode the page url
    $page = urlencode($page);
    # Get the metric information from Google
    $before = date('Y-m-d', strtotime('-' . $days . ' days'));
    $yesterday = date('Y-m-d', strtotime('-1 day'));
    $stats = $api->getMetrics('ga:visits', $before, $yesterday, 'ga:pagePath', false, 'ga:pagePath%3D%3D' . $page, 1);
    # Check the size of the stats array
    if (count($stats) <= 0 || !is_array($stats)) {
        return 0;
    } else {
        # Loop through each stat for display
        foreach ($stats as $stat) {
            return $stat['ga:visits'];
        }
    }
}
function ga_options_page()
{
    // If we are a postback, store the options
    if (isset($_POST['info_update'])) {
        # Verify nonce
        check_admin_referer('google-analyticator-update_settings');
        update_option('ga_defaults', 'no');
        // Update the status
        $ga_status = wp_filter_kses($_POST[key_ga_status]);
        if ($ga_status != ga_enabled && $ga_status != ga_disabled) {
            $ga_status = ga_status_default;
        }
        update_option(key_ga_status, $ga_status);
        // Update the UID
        $ga_uid = wp_filter_kses($_POST[key_ga_uid]);
        if ($ga_uid == '') {
            $ga_uid = ga_uid_default;
        }
        update_option(key_ga_uid, $ga_uid);
        // Update the admin logging
        $ga_admin = wp_filter_kses($_POST[key_ga_admin]);
        if ($ga_admin != ga_enabled && $ga_admin != ga_disabled) {
            $ga_admin = ga_admin_default;
        }
        update_option(key_ga_admin, wp_filter_kses($ga_admin));
        // Update the admin disable setting
        $ga_admin_disable = wp_filter_kses($_POST[key_ga_admin_disable]);
        if ($ga_admin_disable == '') {
            $ga_admin_disable = ga_admin_disable_default;
        }
        update_option(key_ga_admin_disable, wp_filter_kses($ga_admin_disable));
        // Update the admin level
        if (array_key_exists(key_ga_admin_role, $_POST)) {
            $ga_admin_role = $_POST[key_ga_admin_role];
        } else {
            $ga_admin_role = "";
        }
        update_option(key_ga_admin_role, $ga_admin_role);
        // Update the dashboard level
        if (array_key_exists(key_ga_dashboard_role, $_POST)) {
            $ga_dashboard_role = $_POST[key_ga_dashboard_role];
        } else {
            $ga_dashboard_role = "";
        }
        update_option(key_ga_dashboard_role, $ga_dashboard_role);
        // Update the extra tracking code
        $ga_extra = $_POST[key_ga_extra];
        update_option(key_ga_extra, wp_filter_kses($ga_extra));
        // Update the extra after tracking code
        $ga_extra_after = $_POST[key_ga_extra_after];
        update_option(key_ga_extra_after, wp_filter_kses($ga_extra_after));
        // Update the adsense key
        $ga_adsense = $_POST[key_ga_adsense];
        update_option(key_ga_adsense, wp_filter_kses($ga_adsense));
        // Update the event tracking
        $ga_event = $_POST[key_ga_event];
        if ($ga_event != ga_enabled && $ga_event != ga_disabled) {
            $ga_event = ga_event_default;
        }
        update_option(key_ga_event, wp_filter_kses($ga_event));
        // Update the outbound tracking
        $ga_outbound = $_POST[key_ga_outbound];
        if ($ga_outbound != ga_enabled && $ga_outbound != ga_disabled) {
            $ga_outbound = ga_outbound_default;
        }
        update_option(key_ga_outbound, wp_filter_kses($ga_outbound));
        // Update the outbound prefix
        $ga_outbound_prefix = $_POST[key_ga_outbound_prefix];
        if ($ga_outbound_prefix == '') {
            $ga_outbound_prefix = ga_outbound_prefix_default;
        }
        update_option(key_ga_outbound_prefix, wp_filter_kses($ga_outbound_prefix));
        // Update the download tracking code
        $ga_downloads = $_POST[key_ga_downloads];
        update_option(key_ga_downloads, wp_filter_kses($ga_downloads));
        // Update the download prefix
        $ga_downloads_prefix = $_POST[key_ga_downloads_prefix];
        if ($ga_downloads_prefix == '') {
            $ga_downloads_prefix = ga_downloads_prefix_default;
        }
        update_option(key_ga_downloads_prefix, wp_filter_kses($ga_downloads_prefix));
        // Update the widgets option
        $ga_widgets = $_POST[key_ga_widgets];
        if ($ga_widgets != ga_enabled && $ga_widgets != ga_disabled) {
            $ga_widgets = ga_widgets_default;
        }
        update_option(key_ga_widgets, wp_filter_kses($ga_widgets));
        // Update the widgets option
        update_option(key_ga_annon, wp_filter_kses($_POST[key_ga_annon]));
        // Give an updated message
        echo "<div class='updated fade'><p><strong>" . __('Google Analyticator settings saved.', 'google-analyticator') . "</strong></p></div>";
    }
    // Are we using the auth system?
    $useAuth = get_option('ga_google_token') == '' ? false : true;
    // Output the options page
    ?>

		<div class="wrap">

		<h2><?php 
    _e('Google Analyticator Settings', 'google-analyticator');
    ?>
</h2>
		<form method="post" action="<?php 
    echo admin_url('options-general.php?page=google-analyticator.php');
    ?>
">
			<?php 
    # Add a nonce
    wp_nonce_field('google-analyticator-update_settings');
    ?>

			<?php 
    if (get_option(key_ga_status) == ga_disabled) {
        ?>
				<div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
				<?php 
        _e('Google Analytics integration is currently <strong>DISABLED</strong>.', 'google-analyticator');
        ?>
				</div>
			<?php 
    }
    ?>
			<?php 
    if (get_option(key_ga_uid) == "XX-XXXXX-X" && get_option(key_ga_status) != ga_disabled) {
        ?>
				<div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
				<?php 
        _e('Google Analytics integration is currently enabled, but you did not enter a UID. Tracking will not occur.', 'google-analyticator');
        ?>
				</div>
			<?php 
    }
    ?>
			<table class="form-table" cellspacing="2" cellpadding="5" width="100%">

                            <tr>
                                <td colspan="2">
                                    <h3><?php 
    _e('Basic Settings', 'google-analyticator');
    ?>
</h3>
                                </td>
                            </tr>

				<tr>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_status;
    ?>
"><?php 
    _e('Google Analytics logging is', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<select name='" . key_ga_status . "' id='" . key_ga_status . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_status) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_status) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
					</td>
				</tr>
				<tr id="ga_ajax_accounts">
					<th valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_uid;
    ?>
"><?php 
    _e('Google Analytics UID', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
                                            <?php 
    if ($useAuth) {
        $uids = ga_get_analytics_accounts();
        echo "<select name='" . key_ga_uid . "'> ";
        $hasSelected = false;
        // Will be set to true once a match is found. Cant echo selected twice.
        foreach ($uids as $id => $domain) {
            echo '<option value="' . $id . '"';
            // If set in DB.
            if (get_option(key_ga_uid) == $id) {
                $hasSelected = true;
                echo ' selected="selected"';
            } elseif ($_SERVER['HTTP_HOST'] == $domain && !$hasSelected) {
                $hasSelected = true;
                echo ' selected="selected"';
            }
            echo '>' . $domain . '</option>';
        }
        echo '</select>';
    } else {
        echo '<input type="text" name="' . key_ga_uid . '" value="' . get_option(key_ga_uid) . '" />';
    }
    ?>
					</td>
				</tr>
                                <tr>
                                    <td colspan="2">
                                        <h3><?php 
    _e('Tracking Settings', 'google-analyticator');
    ?>
</h3>
                                    </td>
                                </tr>
				<tr>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_admin;
    ?>
"><?php 
    _e('Track all logged in WordPress users', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<select name='" . key_ga_admin . "' id='" . key_ga_admin . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_admin) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_admin) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('No', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Selecting "no" to this option will prevent logged in WordPress users from showing up on your Google Analytics reports. This setting will prevent yourself or other users from showing up in your Analytics reports. Use the next setting to determine what user groups to exclude.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
                                <tr>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label><?php 
    _e('Anonymize IP Addresses', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<select name='" . key_ga_annon . "' id='" . key_ga_annon . "'>\n";
    echo "<option value='0'";
    if (get_option(key_ga_annon) == false) {
        echo " selected='selected'";
    }
    echo ">" . __('No', 'google-analyticator') . "</option>\n";
    echo "<option value='1'";
    if (get_option(key_ga_annon) == true) {
        echo " selected='selected'";
    }
    echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('By selecting "Yes", This tells Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage. Note that this will slightly reduce the accuracy of geographic reporting.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
				<tr>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_admin_role;
    ?>
"><?php 
    _e('User roles to not track', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    global $wp_roles;
    $roles = $wp_roles->get_names();
    $selected_roles = get_option(key_ga_admin_role);
    if (!is_array($selected_roles)) {
        $selected_roles = array();
    }
    # Loop through the roles
    foreach ($roles as $role => $name) {
        echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
        if (in_array($role, $selected_roles)) {
            echo " checked='checked'";
        }
        $name_pos = strpos($name, '|');
        $name = $name_pos ? substr($name, 0, $name_pos) : $name;
        echo ' /> ' . _x($name, 'User role') . '<br />';
    }
    ?>
						<p  class="setting-description"><?php 
    _e('Specifies the user roles to not include in your WordPress Analytics report. If a user is logged into WordPress with one of these roles, they will not show up in your Analytics report.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
				<tr>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_admin_disable;
    ?>
"><?php 
    _e('Method to prevent tracking', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<select name='" . key_ga_admin_disable . "' id='" . key_ga_admin_disable . "'>\n";
    echo "<option value='remove'";
    if (get_option(key_ga_admin_disable) == 'remove') {
        echo " selected='selected'";
    }
    echo ">" . __('Remove', 'google-analyticator') . "</option>\n";
    echo "<option value='admin'";
    if (get_option(key_ga_admin_disable) == 'admin') {
        echo " selected='selected'";
    }
    echo ">" . __('Use \'admin\' variable', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Selecting the "Remove" option will physically remove the tracking code from logged in users. Selecting the "Use \'admin\' variable" option will assign a variable called \'admin\' to logged in users. This option will allow Google Analytics\' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from pageviews with the \'admin\' variable.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
                                <tr>
                                    <td colspan="2">
                                        <h3>Link Tracking Settings</h3>
                                    </td>
                                </tr>
				<tr>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_outbound;
    ?>
"><?php 
    _e('Outbound link tracking', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<select name='" . key_ga_outbound . "' id='" . key_ga_outbound . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_outbound) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_outbound) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Disabling this option will turn off the tracking of outbound links. It\'s recommended not to disable this option unless you\'re a privacy advocate (now why would you be using Google Analytics in the first place?) or it\'s causing some kind of weird issue.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
				<tr>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_event;
    ?>
"><?php 
    _e('Event tracking', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<select name='" . key_ga_event . "' id='" . key_ga_event . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_event) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_event) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Enabling this option will treat outbound links and downloads as events instead of pageviews. Since the introduction of <a href="https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide">event tracking in Analytics</a>, this is the recommended way to track these types of actions. Only disable this option if you must use the old pageview tracking method.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
				<tr>
					<th valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_downloads;
    ?>
"><?php 
    _e('Download extensions to track', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_downloads . "' ";
    echo "id='" . key_ga_downloads . "' ";
    echo "value='" . wp_filter_kses(get_option(key_ga_downloads)) . "' />\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Enter any extensions of files you would like to be tracked as a download. For example to track all MP3s and PDFs enter <strong>mp3,pdf</strong>. <em>Outbound link tracking must be enabled for downloads to be tracked.</em>', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
				<tr>
					<th valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_outbound_prefix;
    ?>
"><?php 
    _e('Prefix external links with', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_outbound_prefix . "' ";
    echo "id='" . key_ga_outbound_prefix . "' ";
    echo "value='" . stripslashes(wp_filter_kses(get_option(key_ga_outbound_prefix))) . "' />\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Enter a name for the section tracked external links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator');
    ?>
</em></p>
					</td>
				</tr>
				<tr>
					<th valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_downloads_prefix;
    ?>
"><?php 
    _e('Prefix download links with', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_downloads_prefix . "' ";
    echo "id='" . key_ga_downloads_prefix . "' ";
    echo "value='" . stripslashes(wp_filter_kses(get_option(key_ga_downloads_prefix))) . "' />\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Enter a name for the section tracked download links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator');
    ?>
</em></p>
					</td>
				</tr>
				<tr>
					<th valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_adsense;
    ?>
"><?php 
    _e('Google Adsense ID', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_adsense . "' ";
    echo "id='" . key_ga_adsense . "' ";
    echo "value='" . get_option(key_ga_adsense) . "' />\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Enter your Google Adsense ID assigned by Google Analytics in this box. This enables Analytics tracking of Adsense information if your Adsense and Analytics accounts are linked.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
                                <tr>
                                    <td colspan="2">
                                        <h3>Additional Tracking Code </h3>
                                    </td>
                                </tr>
				<tr>
					<th valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_extra;
    ?>
"><?php 
    _e('Additional tracking code', 'google-analyticator');
    ?>
<br />(<?php 
    _e('before tracker initialization', 'google-analyticator');
    ?>
):</label>
					</th>
					<td>
						<?php 
    echo "<textarea cols='50' rows='8' ";
    echo "name='" . key_ga_extra . "' ";
    echo "id='" . key_ga_extra . "'>";
    echo stripslashes(get_option(key_ga_extra)) . "</textarea>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>before</strong> the Google Analytics tracker is initialized.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
				<tr>
					<th valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_extra_after;
    ?>
"><?php 
    _e('Additional tracking code', 'google-analyticator');
    ?>
<br />(<?php 
    _e('after tracker initialization', 'google-analyticator');
    ?>
):</label>
					</th>
					<td>
						<?php 
    echo "<textarea cols='50' rows='8' ";
    echo "name='" . key_ga_extra_after . "' ";
    echo "id='" . key_ga_extra_after . "'>";
    echo stripslashes(get_option(key_ga_extra_after)) . "</textarea>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>after</strong> the Google Analytics tracker is initialized.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
				<tr>
                                    <td colspan="2">
                                        <h3>Admin Dashboard Widgets</h3>
                                        <?php 
    if (!$useAuth) {
        ?>
                                        <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
                                            <?php 
        _e('You have not authenticated with Google - you cannot use dashboard widgets! Reset the plugin to authenticate..', 'google-analyticator');
        ?>
                                        </div>
                                        <?php 
    }
    ?>
                                    </td>
                                </tr>
                                <tr<?php 
    if (!$useAuth) {
        echo ' style="display:none"';
    }
    ?>
>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_widgets;
    ?>
"><?php 
    _e('Include widgets', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    echo "<select name='" . key_ga_widgets . "' id='" . key_ga_widgets . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_widgets) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_widgets) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
						<p  class="setting-description"><?php 
    _e('Disabling this option will completely remove the Dashboard Summary widget and the theme Stats widget. Use this option if you would prefer to not see the widgets.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>
                                <tr<?php 
    if (!$useAuth) {
        echo ' style="display:none"';
    }
    ?>
>
					<th width="30%" valign="top" style="padding-top: 10px;">
						<label for="<?php 
    echo key_ga_dashboard_role;
    ?>
"><?php 
    _e('User roles that can see the dashboard widget', 'google-analyticator');
    ?>
:</label>
					</th>
					<td>
						<?php 
    global $wp_roles;
    $roles = $wp_roles->get_names();
    $selected_roles = get_option(key_ga_dashboard_role);
    if (!is_array($selected_roles)) {
        $selected_roles = array();
    }
    # Loop through the roles
    foreach ($roles as $role => $name) {
        echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
        if (in_array($role, $selected_roles)) {
            echo " checked='checked'";
        }
        $name_pos = strpos($name, '|');
        $name = $name_pos ? substr($name, 0, $name_pos) : $name;
        echo ' /> ' . _x($name, 'User role') . '<br />';
    }
    ?>
						<p  class="setting-description"><?php 
    _e('Specifies the user roles that can see the dashboard widget. If a user is not in one of these role groups, they will not see the dashboard widget.', 'google-analyticator');
    ?>
</p>
					</td>
				</tr>

				</table>
			<p class="submit">
				<input type="submit" class="button button-primary" name="info_update" value="<?php 
    _e('Save Changes', 'google-analyticator');
    ?>
" />
			</p>

                        <a href="<?php 
    echo admin_url('/options-general.php?page=ga_reset');
    ?>
"><?php 
    _e('Deauthorize &amp; Reset Google Analyticator.', 'google-analyticator');
    ?>
</a>

                </form>


<?php 
    if (!get_option('wpm_o_user_id')) {
        ?>
    <img src="<?php 
        echo plugins_url('wlcms-plugin-advert.png', __FILE__);
        ?>
" alt="Learn how to make WordPress better" />
    <form method="post" onsubmit="return quickValidate()"  action="http://www.aweber.com/scripts/addlead.pl" target="_blank" >
    <div style="display: none;">
    <input type="hidden" name="meta_web_form_id" value="672327302" />
    <input type="hidden" name="meta_split_id" value="" />
    <input type="hidden" name="listname" value="vumpublic2" />
    <input type="hidden" name="redirect" value="http://www.aweber.com/thankyou-coi.htm?m=video" id="redirect_9567c93ed4b6fb0c7cd9247553c362eb" />
    <input type="hidden" name="meta_adtracking" value="ga-plugin" />
    <input type="hidden" name="meta_message" value="1" />
    <input type="hidden" name="meta_required" value="name,email" />
    <input type="hidden" name="meta_tooltip" value="" />
    </div>
    <table style="text-align:center;margin-left: 20px;">
    <tr>
    <td><label class="previewLabel" for="awf_field-37978044"><strong>Name: </strong></label><input id="sub_name" type="text" name="name" class="text"  tabindex="500" value="" /></td>
    <td><label class="previewLabel" for="awf_field-37978045"><strong>Email: </strong></label> <input class="text" id="sub_email" type="text" name="email" tabindex="501"  value="" /></td>
    <td><span class="submit"><input name="submit" type="image" alt="submit" tabindex="502" src="<?php 
        echo plugins_url('download-button.png', __FILE__);
        ?>
" width="157" height="40" style="background: none; border: 0;" /></span></td>
    </tr>
    <tr>
    <td colspan="3" style="padding-top: 20px;">
    <a title="Privacy Policy" href="http://www.aweber.com/permission.htm" target="_blank"><img src="<?php 
        echo plugins_url('privacy.png', __FILE__);
        ?>
"  alt="" title="" /></a>
    </td>
    </tr>
    </table>
    </form>
<?php 
    }
    ?>

<script type="text/javascript">
function quickValidate()
{
        if (! jQuery('#sub_name').val() )
            {
                alert('Your Name is required');
                return false;
            }
        if(! jQuery('#sub_email').val() )
            {
                alert('Your Email is required');
                return false;
            }

            return true;

}
</script>

		</div>
		</form>

<?php 
}
Beispiel #3
0
function ga_options_page()
{
    // If we are a postback, store the options
    if (isset($_POST['info_update'])) {
        # Verify nonce
        check_admin_referer('google-analyticator-update_settings');
        update_option('ga_defaults', 'no');
        // Get our domains array, and match the UID to the value
        $domains = stripslashes($_POST['ga_domain_names']);
        $all_domains = unserialize($domains);
        update_option('ga_domain_name', $all_domains[$_POST[key_ga_uid]]);
        // Update the status
        $ga_status = wp_filter_kses($_POST[key_ga_status]);
        if ($ga_status != ga_enabled && $ga_status != ga_disabled) {
            $ga_status = ga_status_default;
        }
        update_option(key_ga_status, $ga_status);
        // Update Hiding UID (if set)
        if (isset($_POST[key_ga_disable_gasites])) {
            $ga_disable_gasites = wp_filter_kses($_POST[key_ga_disable_gasites]);
            if (!$ga_disable_gasites) {
                $ga_disable_gasites = ga_disable_gasites_default;
            }
            update_option(key_ga_disable_gasites, $ga_disable_gasites);
        }
        // Update the Analytic Snippet
        //define("key_ga_analytic_snippet", "ga_analytic_snippet", true);
        $ga_analytic_snippet = wp_filter_kses($_POST[key_ga_analytic_snippet]);
        if ($ga_analytic_snippet != ga_enabled && $ga_analytic_snippet != ga_disabled) {
            $ga_analytic_snippet = ga_analytic_snippet;
        }
        update_option(key_ga_analytic_snippet, $ga_analytic_snippet);
        // Update the UID
        $ga_uid = wp_filter_kses($_POST[key_ga_uid]);
        if ($ga_uid == '') {
            $ga_uid = ga_uid_default;
        }
        update_option(key_ga_uid, $ga_uid);
        // Update the admin logging
        $ga_admin = wp_filter_kses($_POST[key_ga_admin]);
        if ($ga_admin != ga_enabled && $ga_admin != ga_disabled) {
            $ga_admin = ga_admin_default;
        }
        update_option(key_ga_admin, wp_filter_kses($ga_admin));
        // Update the Dimension Index
        $ga_admin_disable_DimentionIndex = $_POST[key_ga_admin_disable_DimentionIndex];
        if ($ga_admin_disable_DimentionIndex == '') {
            $ga_admin_disable_DimentionIndex = ga_admin_disable_DimentionIndex_default;
        }
        update_option(key_ga_admin_disable_DimentionIndex, wp_filter_kses($ga_admin_disable_DimentionIndex));
        // Update the admin disable setting
        $ga_admin_disable = wp_filter_kses($_POST[key_ga_admin_disable]);
        if ($ga_admin_disable == '') {
            $ga_admin_disable = ga_admin_disable_default;
        }
        update_option(key_ga_admin_disable, wp_filter_kses($ga_admin_disable));
        // Update the admin level
        if (array_key_exists(key_ga_admin_role, $_POST)) {
            $ga_admin_role = $_POST[key_ga_admin_role];
        } else {
            $ga_admin_role = "";
        }
        update_option(key_ga_admin_role, $ga_admin_role);
        // Update the dashboard level
        if (array_key_exists(key_ga_dashboard_role, $_POST)) {
            $ga_dashboard_role = $_POST[key_ga_dashboard_role];
        } else {
            $ga_dashboard_role = "";
        }
        update_option(key_ga_dashboard_role, $ga_dashboard_role);
        // Update the extra tracking code
        $ga_extra = $_POST[key_ga_extra];
        update_option(key_ga_extra, wp_filter_kses($ga_extra));
        // Update the extra after tracking code
        $ga_extra_after = $_POST[key_ga_extra_after];
        update_option(key_ga_extra_after, wp_filter_kses($ga_extra_after));
        // Update the adsense key
        $ga_adsense = $_POST[key_ga_adsense];
        update_option(key_ga_adsense, wp_filter_kses($ga_adsense));
        // Update the event tracking
        $ga_event = $_POST[key_ga_event];
        if ($ga_event != ga_enabled && $ga_event != ga_disabled) {
            $ga_event = ga_event_default;
        }
        update_option(key_ga_event, wp_filter_kses($ga_event));
        // Update the outbound tracking
        $ga_outbound = $_POST[key_ga_outbound];
        if ($ga_outbound != ga_enabled && $ga_outbound != ga_disabled) {
            $ga_outbound = ga_outbound_default;
        }
        update_option(key_ga_outbound, wp_filter_kses($ga_outbound));
        // Update the outbound prefix
        $ga_outbound_prefix = $_POST[key_ga_outbound_prefix];
        if ($ga_outbound_prefix == '') {
            $ga_outbound_prefix = ga_outbound_prefix_default;
        }
        update_option(key_ga_outbound_prefix, wp_filter_kses($ga_outbound_prefix));
        // Update the download tracking code
        $ga_downloads = $_POST[key_ga_downloads];
        update_option(key_ga_downloads, wp_filter_kses($ga_downloads));
        // Update the Enhanced Link Attribution
        $ga_enhanced_link_attr = $_POST[key_ga_enhanced_link_attr];
        if ($ga_enhanced_link_attr == '') {
            $ga_enhanced_link_attr = ga_enhanced_link_attr_default;
        }
        update_option(key_ga_enhanced_link_attr, wp_filter_kses($ga_enhanced_link_attr));
        // Update the download prefix
        $ga_downloads_prefix = $_POST[key_ga_downloads_prefix];
        if ($ga_downloads_prefix == '') {
            $ga_downloads_prefix = ga_downloads_prefix_default;
        }
        update_option(key_ga_downloads_prefix, wp_filter_kses($ga_downloads_prefix));
        // Update the widgets option
        $ga_widgets = $_POST[key_ga_widgets];
        if ($ga_widgets != ga_enabled && $ga_widgets != ga_disabled) {
            $ga_widgets = ga_widgets_default;
        }
        update_option(key_ga_widgets, wp_filter_kses($ga_widgets));
        // Update the widgets option
        update_option(key_ga_annon, wp_filter_kses($_POST[key_ga_annon]));
        // Update enable remarketing
        update_option(key_ga_remarketing, wp_filter_kses($_POST[key_ga_remarketing]));
        // Update key_ga_hide_ad
        update_option(key_ga_show_ad, wp_filter_kses($_POST[key_ga_show_ad]));
        // Update enable tracking login
        update_option(key_ga_track_login, wp_filter_kses($_POST[key_ga_track_login]));
        // Give an updated message
        echo "<div class='updated fade'><p><strong>" . __('Google Analyticator settings saved.', 'google-analyticator') . "</strong></p></div>";
    }
    // Are we using the auth system?
    $useAuth = get_option('ga_google_token') == '' ? false : true;
    // Output the options page
    ?>
<div class="wrap">
  <form method="post" action="<?php 
    echo ga_analyticator_setting_url();
    ?>
">
    <?php 
    # Add a nonce
    wp_nonce_field('google-analyticator-update_settings');
    ?>
    <?php 
    if (get_option(key_ga_status) == ga_disabled) {
        ?>
    <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
      <?php 
        _e('Google Analytics integration is currently <strong>DISABLED</strong>.', 'google-analyticator');
        ?>
    </div>
    <?php 
    }
    ?>
    <?php 
    if (get_option(key_ga_uid) == "XX-XXXXX-X" && get_option(key_ga_status) != ga_disabled) {
        ?>
    <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
      <?php 
        _e('Google Analytics integration is currently enabled, but you did not enter a UID. Tracking will not occur.', 'google-analyticator');
        ?>
    </div>
    <?php 
    }
    ?>
    <div id="vumga-container" style="position:relative;">
    <?php 
    $addons = get_option("gapro_addons");
    if (!$addons) {
        ?>
    <div id="vumga-sidebar" style="position: absolute; top: 0; right: 0; width: 250px; border: 1px solid #ccc; padding: 20px; background:#FFFFFF"> <a href="http://get.videousermanuals.com/ga-pro/?utm_campaign=analyticatorpro&utm_medium=plugin&utm_source=settings" target="_blank"><img src="<?php 
        echo plugins_url('gapro-plugin-advert-sidebar.png', __FILE__);
        ?>
" alt="Learn More" title="Learn More" /></a> </div>
    <?php 
    }
    ?>
    <div style="margin-right: 320px;">
    <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
      <tr>
        <td colspan="2"><h3>
            <?php 
    _e('Basic Settings', 'google-analyticator');
    ?>
          </h3></td>
      </tr>
      
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_status;
    ?>
">
            <?php 
    _e('Google Analytics logging is', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td>
		<?php 
    echo "<select name='" . key_ga_status . "' id='" . key_ga_status . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_status) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_status) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
       
       </td>
      </tr>
      <tr id="ga_ajax_accounts">
        <th valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_uid;
    ?>
"> 
            <?php 
    _e('Analytics Account', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td>
		
		<?php 
    if (get_option(key_ga_disable_gasites) == ga_disabled) {
        ?>
		<?php 
        if ($useAuth) {
            $uids = ga_get_analytics_accounts();
            echo "<select name='" . key_ga_uid . "'> ";
            $hasSelected = false;
            // Will be set to true once a match is found. Cant echo selected twice.
            foreach ($uids as $id => $domain) {
                echo '<option value="' . $id . '"';
                // If set in DB.
                if (get_option(key_ga_uid) == $id) {
                    $hasSelected = true;
                    echo ' selected="selected"';
                } elseif ($_SERVER['HTTP_HOST'] == $domain && !$hasSelected) {
                    $hasSelected = true;
                    echo ' selected="selected"';
                }
                echo '>' . $domain . '</option>';
            }
            echo '</select>';
            // Need a copy of the array, so we can store the domain name too (for visual purposes)
            echo '<input type="hidden" name="ga_domain_names" value=\'' . serialize($uids) . '\' />';
        } else {
            echo '<input type="text" name="' . key_ga_uid . '" value="' . get_option(key_ga_uid) . '" />';
        }
        ?>
<br />
                        <input type="checkbox" name="<?php 
        echo key_ga_disable_gasites;
        ?>
" id="<?php 
        echo key_ga_disable_gasites;
        ?>
"<?php 
        if (get_option(key_ga_disable_gasites) == ga_enabled) {
            ?>
 checked="checked"<?php 
        }
        ?>
 /> <?php 
        _e('Hide Google Analytics UID after saving', 'google-analyticator');
        ?>
         	<?php 
    } else {
        echo get_option('ga_domain_name');
        ?>
 - To change this, you must <a href="<?php 
        echo admin_url('/options-general.php?page=ga_reset');
        ?>
">deauthorize and reset the plugin</a>
			 <input type="hidden" name="<?php 
        echo key_ga_disable_gasites;
        ?>
" value="<?php 
        echo ga_enabled;
        ?>
" /><input type="hidden" name="<?php 
        echo key_ga_uid;
        ?>
" value="<?php 
        echo get_option(key_ga_uid);
        ?>
" />
			<?php 
    }
    ?>
               
         </td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_analytic_snippet;
    ?>
">
            <?php 
    _e('Tracking Code', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_analytic_snippet . "' id='" . key_ga_analytic_snippet . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_analytic_snippet) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Traditional (ga.js)', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_analytic_snippet) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Universal (analytics.js)', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
					  <p  class="setting-description">
						<?php 
    _e('If you are using Universal Analytics make sure you have changed your account to a Universal Analytics property in Google Analytics. Read more about Universal Analytics <a href="https://support.google.com/analytics/answer/2817075?hl=en" target="_blank">here</a>.', 'google-analyticator');
    ?>
					  </p>						
						
						</td>
      </tr>
      <tr>
        <td colspan="2"><h3>
            <?php 
    _e('Tracking Settings', 'google-analyticator');
    ?>
          </h3></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_admin;
    ?>
">
            <?php 
    _e('Track all logged in WordPress users', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_admin . "' id='" . key_ga_admin . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_admin) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_admin) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('No', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Selecting "no" to this option will prevent logged in WordPress users from showing up on your Google Analytics reports. This setting will prevent yourself or other users from showing up in your Analytics reports. Use the next setting to determine what user groups to exclude.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label>
            <?php 
    _e('Anonymize IP Addresses', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_annon . "' id='" . key_ga_annon . "'>\n";
    echo "<option value='0'";
    if (get_option(key_ga_annon) == false) {
        echo " selected='selected'";
    }
    echo ">" . __('No', 'google-analyticator') . "</option>\n";
    echo "<option value='1'";
    if (get_option(key_ga_annon) == true) {
        echo " selected='selected'";
    }
    echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('By selecting "Yes", This tells Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage. Note that this will slightly reduce the accuracy of geographic reporting.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_admin_role;
    ?>
">
            <?php 
    _e('User roles to not track', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    global $wp_roles;
    $roles = $wp_roles->get_names();
    $selected_roles = get_option(key_ga_admin_role);
    if (!is_array($selected_roles)) {
        $selected_roles = array();
    }
    # Loop through the roles
    foreach ($roles as $role => $name) {
        echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
        if (in_array($role, $selected_roles)) {
            echo " checked='checked'";
        }
        $name_pos = strpos($name, '|');
        $name = $name_pos ? substr($name, 0, $name_pos) : $name;
        echo ' /> ' . _x($name, 'User role') . '<br />';
    }
    ?>
          <p  class="setting-description">
            <?php 
    _e('Specifies the user roles to not include in your WordPress Analytics report. If a user is logged into WordPress with one of these roles, they will not show up in your Analytics report.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_admin_disable;
    ?>
">
            <?php 
    _e('Method to prevent tracking', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_admin_disable . "' id='" . key_ga_admin_disable . "'>\n";
    echo "<option value='remove'";
    if (get_option(key_ga_admin_disable) == 'remove') {
        echo " selected='selected'";
    }
    echo ">" . __('Remove', 'google-analyticator') . "</option>\n";
    echo "<option value='admin'";
    if (get_option(key_ga_admin_disable) == 'admin') {
        echo " selected='selected'";
    }
    echo ">" . __('Use \'admin\' variable', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <span class="ga_admin_disable_DimentionIndex_span"> Dimension Index :
          <input type="text" name="<?php 
    echo key_ga_admin_disable_DimentionIndex;
    ?>
" style="width:50px;" value="<?php 
    echo get_option(key_ga_admin_disable_DimentionIndex);
    ?>
" class="<?php 
    echo key_ga_admin_disable_DimentionIndex;
    ?>
" id="<?php 
    echo key_ga_admin_disable_DimentionIndex;
    ?>
" />
          </span>
          <p  class="setting-description">
            <?php 
    _e('Selecting the "Remove" option will physically remove the tracking code from logged in users. Selecting the "Use \'admin\' variable" option will assign a variable called \'admin\' to logged in users. This option will allow Google Analytics\' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from pageviews with the \'admin\' variable.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label>
            <?php 
    _e('Enable Remarketing, Demographics and Interests reports', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_remarketing . "' id='" . key_ga_remarketing . "'>\n";
    echo "<option value='0'";
    if (get_option(key_ga_remarketing) == '0') {
        echo " selected='selected'";
    }
    echo ">" . __('No', 'google-analyticator') . "</option>\n";
    echo "<option value='1'";
    if (get_option(key_ga_remarketing) == '1') {
        echo " selected='selected'";
    }
    echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('In order to use remarketing, <a href="https://support.google.com/analytics/answer/2611270" target="_blank">please make sure you complete this checklist from Google</a>', 'google-analyticator');
    ?>
          </p>
          <p  class="setting-description">
            <?php 
    _e('To use remarketing, <a href="https://support.google.com/analytics/answer/2884495" target="_blank">Edit permission</a> is required', 'google-analyticator');
    ?>
          </p>
          <p style="color:#FF5B5B" class="newtrackingnote">Universal Analytics (analytics.js) does not currently support this feature <a href="https://developers.google.com/analytics/devguides/collection/upgrade/" target="_blank">learn more</a></p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label>
            <?php 
    _e('Track WordPress Login Page', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_track_login . "' id='" . key_ga_track_login . "'>\n";
    echo "<option value='1'";
    if (get_option(key_ga_track_login) == '1') {
        echo " selected='selected'";
    }
    echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
    echo "<option value='0'";
    if (get_option(key_ga_track_login) == '0') {
        echo " selected='selected'";
    }
    echo ">" . __('No', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('This will track all access to wp-login.php', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <td colspan="2"><h3>Link Tracking Settings</h3></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_outbound;
    ?>
">
            <?php 
    _e('Outbound link tracking', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_outbound . "' id='" . key_ga_outbound . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_outbound) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_outbound) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Disabling this option will turn off the tracking of outbound links. It\'s recommended not to disable this option unless you\'re a privacy advocate (now why would you be using Google Analytics in the first place?) or it\'s causing some kind of weird issue.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_event;
    ?>
">
            <?php 
    _e('Event tracking', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_event . "' id='" . key_ga_event . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_event) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_event) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Enabling this option will treat outbound links and downloads as events instead of pageviews. Since the introduction of <a href="https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide">event tracking in Analytics</a>, this is the recommended way to track these types of actions. Only disable this option if you must use the old pageview tracking method.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_enhanced_link_attr;
    ?>
">
            <?php 
    _e('Enhanced Link Attribution', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_enhanced_link_attr . "' id='" . key_ga_enhanced_link_attr . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_enhanced_link_attr) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_enhanced_link_attr) || get_option(key_ga_enhanced_link_attr) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('You can tag your pages to implement an enhanced link-tracking functionality by enabling this option. <a href="https://support.google.com/analytics/answer/2558867?hl=en" target="_blank">learn more</a>', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_downloads;
    ?>
">
            <?php 
    _e('Download extensions to track', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_downloads . "' ";
    echo "id='" . key_ga_downloads . "' ";
    echo "value='" . wp_filter_kses(get_option(key_ga_downloads)) . "' />\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Enter any extensions of files you would like to be tracked as a download. For example to track all MP3s and PDFs enter <strong>mp3,pdf</strong>. <em>Outbound link tracking must be enabled for downloads to be tracked.</em>', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_outbound_prefix;
    ?>
">
            <?php 
    _e('Prefix external links with', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_outbound_prefix . "' ";
    echo "id='" . key_ga_outbound_prefix . "' ";
    echo "value='" . stripslashes(wp_filter_kses(get_option(key_ga_outbound_prefix))) . "' />\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Enter a name for the section tracked external links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator');
    ?>
            </em></p></td>
      </tr>
      <tr>
        <th valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_downloads_prefix;
    ?>
">
            <?php 
    _e('Prefix download links with', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_downloads_prefix . "' ";
    echo "id='" . key_ga_downloads_prefix . "' ";
    echo "value='" . stripslashes(wp_filter_kses(get_option(key_ga_downloads_prefix))) . "' />\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Enter a name for the section tracked download links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator');
    ?>
            </em></p></td>
      </tr>
      <tr>
        <th valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_adsense;
    ?>
">
            <?php 
    _e('Google Adsense ID', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<input type='text' size='50' ";
    echo "name='" . key_ga_adsense . "' ";
    echo "id='" . key_ga_adsense . "' ";
    echo "value='" . get_option(key_ga_adsense) . "' />\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Enter your Google Adsense ID assigned by Google Analytics in this box. This enables Analytics tracking of Adsense information if your Adsense and Analytics accounts are linked.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <td colspan="2"><h3>Additional Tracking Code </h3></td>
      </tr>
      <tr>
        <th valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_extra;
    ?>
">
            <?php 
    _e('Additional tracking code', 'google-analyticator');
    ?>
            <br />
            (
            <?php 
    _e('before tracker initialization', 'google-analyticator');
    ?>
            ):</label>
        </th>
        <td><?php 
    echo "<textarea cols='50' rows='8' ";
    echo "name='" . key_ga_extra . "' ";
    echo "id='" . key_ga_extra . "'>";
    echo stripslashes(get_option(key_ga_extra)) . "</textarea>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>before</strong> the Google Analytics tracker is initialized.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_extra_after;
    ?>
">
            <?php 
    _e('Additional tracking code', 'google-analyticator');
    ?>
            <br />
            (
            <?php 
    _e('after tracker initialization', 'google-analyticator');
    ?>
            ):</label>
        </th>
        <td><?php 
    echo "<textarea cols='50' rows='8' ";
    echo "name='" . key_ga_extra_after . "' ";
    echo "id='" . key_ga_extra_after . "'>";
    echo stripslashes(get_option(key_ga_extra_after)) . "</textarea>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>after</strong> the Google Analytics tracker is initialized.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <td colspan="2"><h3>Admin Dashboard Widgets</h3>
          <?php 
    if (!$useAuth) {
        ?>
          <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
            <?php 
        _e('You have not authenticated with Google - you cannot use dashboard widgets! Reset the plugin to authenticate..', 'google-analyticator');
        ?>
          </div>
          <?php 
    }
    ?>
</td>
      </tr>
      <tr<?php 
    if (!$useAuth) {
        echo ' style="display:none"';
    }
    ?>
>
        <th width="30%" valign="top" style="padding-top: 10px;"><label for="<?php 
    echo key_ga_widgets;
    ?>
">
            <?php 
    _e('Include widgets', 'google-analyticator');
    ?>
            :</label></th>
        <td><?php 
    echo "<select name='" . key_ga_widgets . "' id='" . key_ga_widgets . "'>\n";
    echo "<option value='" . ga_enabled . "'";
    if (get_option(key_ga_widgets) == ga_enabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
    echo "<option value='" . ga_disabled . "'";
    if (get_option(key_ga_widgets) == ga_disabled) {
        echo " selected='selected'";
    }
    echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('Disabling this option will completely remove the Dashboard Summary widget and the theme Stats widget. Use this option if you would prefer to not see the widgets.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_widgets;
    ?>
">
            <?php 
    _e('Display Ad', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    echo "<select name='" . key_ga_show_ad . "' id='" . key_ga_show_ad . "'>\n";
    echo "<option value='1'";
    if (get_option(key_ga_show_ad) == '1') {
        echo " selected='selected'";
    }
    echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
    echo "<option value='0' ";
    if (get_option(key_ga_show_ad) == '0') {
        echo " selected='selected'";
    }
    echo ">" . __('No', 'google-analyticator') . "</option>\n";
    echo "</select>\n";
    ?>
          <p  class="setting-description">
            <?php 
    _e('You can disable the ad on the admin dashboard.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
      <tr<?php 
    if (!$useAuth) {
        echo ' style="display:none"';
    }
    ?>
>
        <th width="30%" valign="top" style="padding-top: 10px;"> <label for="<?php 
    echo key_ga_dashboard_role;
    ?>
">
            <?php 
    _e('User roles that can see the dashboard widget', 'google-analyticator');
    ?>
            :</label>
        </th>
        <td><?php 
    global $wp_roles;
    $roles = $wp_roles->get_names();
    $selected_roles = get_option(key_ga_dashboard_role);
    if (!is_array($selected_roles)) {
        $selected_roles = array();
    }
    # Loop through the roles
    foreach ($roles as $role => $name) {
        echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
        if (in_array($role, $selected_roles)) {
            echo " checked='checked'";
        }
        $name_pos = strpos($name, '|');
        $name = $name_pos ? substr($name, 0, $name_pos) : $name;
        echo ' /> ' . _x($name, 'User role') . '<br />';
    }
    ?>
          <p  class="setting-description">
            <?php 
    _e('Specifies the user roles that can see the dashboard widget. If a user is not in one of these role groups, they will not see the dashboard widget.', 'google-analyticator');
    ?>
          </p></td>
      </tr>
    </table>
    <p class="submit">
      <input type="submit" class="button button-primary" name="info_update" value="<?php 
    _e('Save Changes', 'google-analyticator');
    ?>
" />
    </p>
    <a href="<?php 
    echo admin_url('/options-general.php?page=ga_reset');
    ?>
">
    <?php 
    _e('Deauthorize &amp; Reset Google Analyticator.', 'google-analyticator');
    ?>
    </a>
  </form>
</div>
</div>
<!-- end wrap -->
</div>
<!-- end vumga-container -->

<?php 
}
/**
 * An AJAX function to get a list of accounts in a drop down
 **/
function ga_ajax_accounts()
{
    # Check the ajax widget
    check_ajax_referer('ga_ajax_accounts');
    # Get the list of accounts if available
    $ga_accounts = ga_get_analytics_accounts();
    if ($ga_accounts !== false) {
        ?>
	
	<th valign="top" style="padding-top: 10px;">
		<label for="<?php 
        echo key_ga_uid;
        ?>
"><?php 
        _e('Google Analytics account', 'google-analyticator');
        ?>
:</label>
	</th>
	<td>
		<?php 
        # Create a select box
        echo '<select name="' . key_ga_uid . '" id="' . key_ga_uid . '">';
        echo '<option value="XX-XXXXX-X">' . __('Select an Account', 'google-analyticator') . '</option>';
        # The list of accounts
        foreach ($ga_accounts as $account) {
            $select = get_option(key_ga_uid) == $account['ga:webPropertyId'] ? ' selected="selected"' : '';
            echo '<option value="' . $account['ga:webPropertyId'] . '"' . $select . '>' . $account['title'] . '</option>';
        }
        # Close the select box
        echo '</select>';
        ?>
		<p style="margin: 5px 10px;" class="setting-description"><?php 
        _e('Select the Analytics account you wish to enable tracking for. An account must be selected for tracking to occur.', 'google-analyticator');
        ?>
</p>
	</td>
	
	<?php 
    }
    die;
}