checkAccessToken(false)) { $hasTokens = true; $checks['profiles'] = $reportingClass->getProfiles(); $checks['matchingProfile'] = $reportingClass->getProfileByProfileId($betterAnalyticsOptions['api']['profile']); $checks['siteSearchSetup'] = @$checks['matchingProfile']['siteSearchQueryParameters'] == 's'; $checks['ecommerceTracking'] = @$checks['matchingProfile']['eCommerceTracking']; $checks['enhancedEcommerceTracking'] = @$checks['matchingProfile']['enhancedECommerceTracking']; $property = $reportingClass->getPropertyByPropertyId(@$checks['matchingProfile']['accountId'], $betterAnalyticsOptions['property_id']); $checks['level'] = @$property['level']; $checks['industryVertical'] = @$property['industryVertical']; $checks['dimensions'] = $reportingClass->getDimensionsByPropertyId(@$checks['matchingProfile']['accountId'], $betterAnalyticsOptions['property_id'], $dimensions); } $checks['licensed'] = DigitalPointBetterAnalytics_Helper_Api::check(true); if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'config') { if (!$hasTokens) { esc_html_e('You need to first link a Google Analytics account to auto-configure it.', 'better-analytics'); } elseif (empty($_REQUEST['vertical'])) { wp_enqueue_script('chosen_js', BETTER_ANALYTICS_PLUGIN_URL . 'assets/chosen/chosen.jquery.min.js', array(), BETTER_ANALYTICS_VERSION ); wp_enqueue_style('chosen_css', BETTER_ANALYTICS_PLUGIN_URL . 'assets/chosen/chosen.min.css', array(), BETTER_ANALYTICS_VERSION); wp_enqueue_script('better-analytics_admin_js', BETTER_ANALYTICS_PLUGIN_URL . 'assets/digitalpoint/js/admin.js', array(), BETTER_ANALYTICS_VERSION ); $verticals = $reportingClass->getIndustryVerticals(); if (!$checks['matchingProfile']) { if ($accounts = $reportingClass->getAccounts()) { $accounts = DigitalPointBetterAnalytics_Model_Reporting::parseAccounts($accounts, true); } if(!$accounts) { $hasAccounts = false; } } else { $accounts = null; } echo '

' . esc_html__('Auto-Configure' , 'better-analytics') . '

'; if ($hasAccounts) { echo '

' . esc_html__('Only use this option if you are sure you want to auto-configure everything.', 'better-analytics') . '

'; echo '
'; echo ''; if ($accounts) { esc_html_e('Please select the Google Analytics account that you wish to create a new Web Property within:', 'better-analytics'); echo '

'; } esc_html_e('Please select the industry vertical that you wish your Web Property to be assigned to:', 'better-analytics'); echo '

'; esc_html_e('This will perform the following actions:', 'better-analytics'); echo ''; submit_button(esc_html__('Auto-Configure', 'better-analytics')); echo '
'; } else { echo '

' . esc_html__('Your linked Google account doesn\'t appear to have any Google Analytics accounts within it. You can link a different Google account or create a Google Analytics account within it.', 'better-analytics') . '

' . esc_html__('Link/Authenticate A Different Google Analytics Account', 'better-analytics') . '' . '   ' . esc_html__('Create Analytics Account Manually Within Your Google Account', 'better-analytics') . '' . '

'; } echo '
'; } elseif($_SERVER['REQUEST_METHOD'] == 'POST') { $vertical = sanitize_text_field($_REQUEST['vertical']); $accountId = empty($_REQUEST['account_id']) ? 0 : absint($_REQUEST['account_id']); $overQuota = false; if ($accountId) { $property = $reportingClass->insertWebProperty($accountId, array( 'industryVertical' => $vertical, 'kind' => 'analytics#webproperty', 'name' => get_option('blogname'), 'websiteUrl' => get_option('siteurl'), )); if ($reportingClass->checkApiErrorType($property, 'noQuota')) { $overQuota = true; } if (!$overQuota && !empty($property['id'])) { $profile = $reportingClass->insertProfile($property['accountId'], $property['id'], array( 'kind' => 'analytics#profile', 'type' => 'WEB', 'name' => 'All Web Site Data', 'timezone' => get_option('timezone_string'), 'websiteUrl' => get_option('siteurl'), 'eCommerceTracking' => true, 'enhancedECommerceTracking' => true, 'siteSearchQueryParameters' => 's', 'stripSiteSearchQueryParameters' => true )); if ($reportingClass->checkApiErrorType($profile, 'noQuota')) { $overQuota = true; } else { $betterAnalyticsOptions['property_id'] = $profile['webPropertyId']; $betterAnalyticsOptions['api']['profile'] = $profile['id']; } // Really seems like an Analytics bug because the enhancedECommerceTracking option doesn't take upon insert, so for now, PATCHing after the fact. // See: https://code.google.com/p/analytics-issues/issues/detail?id=688 if (!$overQuota && !empty($profile['id']) && empty($profile['enhancedECommerceTracking'])) { $profile = $reportingClass->patchProfile($property['accountId'], $property['id'], $profile['id'], array( 'enhancedECommerceTracking' => true, )); if ($reportingClass->checkApiErrorType($profile, 'noQuota')) { $overQuota = true; } } } } else { if (!empty($property['accountId']) && !empty($property['id']) && @$property['industryVertical'] != $vertical) { $property = $reportingClass->patchWebProperty($property['accountId'], $property['id'], array( 'industryVertical' => $vertical )); if ($reportingClass->checkApiErrorType($property, 'noQuota')) { $overQuota = true; } } if ( !$overQuota && !empty($property['accountId']) && !empty($property['id']) && !empty($betterAnalyticsOptions['api']['profile']) && ( empty($check['matchingProfile']['eCommerceTracking']) || empty($check['matchingProfile']['enhancedECommerceTracking']) || @$check['matchingProfile']['siteSearchQueryParameters'] != 's' || empty($check['matchingProfile']['stripSiteSearchQueryParameters']) ) ) { $profile = $reportingClass->patchProfile($property['accountId'], $property['id'], $betterAnalyticsOptions['api']['profile'], array( 'eCommerceTracking' => true, 'enhancedECommerceTracking' => true, 'siteSearchQueryParameters' => 's', 'stripSiteSearchQueryParameters' => true )); if ($reportingClass->checkApiErrorType($profile, 'noQuota')) { $overQuota = true; } } } foreach ($dimensions as $dimension) { if (empty($checks['dimensions'][$dimension])) { $results = $reportingClass->insertCustomDimension($property['accountId'], $property['id'], array( 'name' => $dimension, 'scope' => 'HIT', 'active' => true )); if ($reportingClass->checkApiErrorType($results, 'noQuota')) { $overQuota = true; break; } } } if ($overQuota) { set_transient('ba_last_error', esc_html__('Google API Quota Exceeded (you will need to configure your Google Analytics account manually).'), 10); } $reportingClass->deleteProfileCache(); $reportingClass->deleteProfileCache($property['accountId'], null); $reportingClass->deleteDimensionCache($property['accountId'], $property['id']); $checks['dimensions'] = $reportingClass->getDimensionsByPropertyId($property['accountId'], $property['id'], $dimensions); foreach ($dimensions as $dimension) { if (!empty($checks['dimensions'][$dimension])) { $dimLower = strtolower($dimension); // Blah... ugly renaming if ($dimLower == 'tags') { $dimLower = 'tag'; } elseif ($dimLower == 'categories') { $dimLower = 'category'; } $betterAnalyticsOptions['dimension'][$dimLower] = $checks['dimensions'][$dimension]['index']; } } update_option('better_analytics', $betterAnalyticsOptions); wp_redirect(esc_url(menu_page_url('better-analytics_test', false)), 302); } } else { ?>

✓' : ''); ?> ✓' : ''); ?> */ ?> ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > ✓' : ''); ?> > 0 && @$checks['dimensions']['Categories']['index'] == $betterAnalyticsOptions['dimension']['category'] ? '' : ''); ?> > 0 && @$checks['dimensions']['Author']['index'] == $betterAnalyticsOptions['dimension']['author'] ? '' : ''); ?> > 0 && @$checks['dimensions']['Tags']['index'] == $betterAnalyticsOptions['dimension']['tag'] ? '' : ''); ?> > 0 && @$checks['dimensions']['Year']['index'] == $betterAnalyticsOptions['dimension']['year'] ? '' : ''); ?> > 0 && @$checks['dimensions']['Role']['index'] == $betterAnalyticsOptions['dimension']['role'] ? '' : ''); ?> > 0 && @$checks['dimensions']['User']['index'] == $betterAnalyticsOptions['dimension']['user'] ? '' : ''); ?> ✓' : ''); ?>

%2$s:', 'https://php.net/manual/en/curl.installation.php', esc_html__('cURL Installed', 'better-analytics'));?> ✗
%2$s:', menu_page_url('better-analytics', false) . '#top#api', esc_html__('API Project Credentials', 'better-analytics'));?> ✗
%2$s:', menu_page_url('better-analytics', false) . '#top#api', esc_html__('Google Analytics Account Linked', 'better-analytics'));?> ✗


%2$s:', menu_page_url('better-analytics', false) . '#top#general', esc_html__('Web Property ID Defined', 'better-analytics'));?> ✗
%2$s:', menu_page_url('better-analytics', false) . '#top#api', esc_html__('Analytics Profile Selected', 'better-analytics'));?> ✗
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Site Search Setup', 'better-analytics'));?> ✗ , %2$s = */ printf(__('Found in Google Analytics account under %1$sView Settings -> Query Parameter%2$s (should be set to "%1$ss%2$s").', 'better-analytics'), '', ''); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Ecommerce Tracking Enabled', 'better-analytics'));?> ✗ , %2$s = */ printf(__('Found in Google Analytics account under %1$sEcommerce Settings%2$s.', 'better-analytics'), '', ''); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Enhanced Ecommerce Tracking Enabled', 'better-analytics'));?> ✗ , %2$s = */ printf(esc_html__('Found in Google Analytics account under %1$sEcommerce Settings%2$s.', 'better-analytics'), '', ''); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Industry Vertical Set', 'better-analytics'));?> ✗ , %2$s = , %3$s = current setting in Google Analytics account */ printf(esc_html__('Found in Google Analytics account under %1$sProperty Settings%2$s (currently set to %1$s%3$s%2$s).', 'better-analytics'), '', '', ($checks['industryVertical'] ? $checks['industryVertical'] : 'UNSPECIFIED')); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Custom Dimension For Category Tracking', 'better-analytics'));?> ✗ , %2$s = ... %3$s can't be translated - leave */ printf(esc_html__('Found in Google Analytics account under %1$sCustom Definitions -> Custom Dimensions%2$s (should be named "%1$s%3$s%2$s" and scoped for "%1$sHit%2$s").', 'better-analytics'), '', '', 'Categories'); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Custom Dimension For Author Tracking', 'better-analytics'));?> ✗ , %2$s = ... %3$s can't be translated - leave */ printf(esc_html__('Found in Google Analytics account under %1$sCustom Definitions -> Custom Dimensions%2$s (should be named "%1$s%3$s%2$s" and scoped for "%1$sHit%2$s").', 'better-analytics'), '', '', 'Author'); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Custom Dimension For Tag Tracking', 'better-analytics'));?> ✗ , %2$s = ... %3$s can't be translated - leave */ printf(esc_html__('Found in Google Analytics account under %1$sCustom Definitions -> Custom Dimensions%2$s (should be named "%1$s%3$s%2$s" and scoped for "%1$sHit%2$s").', 'better-analytics'), '', '', 'Tags'); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Custom Dimension For Publication Year Tracking', 'better-analytics'));?> ✗ , %2$s = ... %3$s can't be translated - leave */ printf(esc_html__('Found in Google Analytics account under %1$sCustom Definitions -> Custom Dimensions%2$s (should be named "%1$s%3$s%2$s" and scoped for "%1$sHit%2$s").', 'better-analytics'), '', '', 'Year'); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Custom Dimension For User Role Tracking', 'better-analytics'));?> ✗ , %2$s = ... %3$s can't be translated - leave */ printf(esc_html__('Found in Google Analytics account under %1$sCustom Definitions -> Custom Dimensions%2$s (should be named "%1$s%3$s%2$s" and scoped for "%1$sHit%2$s").', 'better-analytics'), '', '', 'Role'); ?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Custom Dimension For User Tracking', 'better-analytics'));?> ✗ , %2$s = ... %3$s can't be translated - leave */ printf(esc_html__('Found in Google Analytics account under %1$sCustom Definitions -> Custom Dimensions%2$s (should be named "%1$s%3$s%2$s" and scoped for "%1$sHit%2$s").', 'better-analytics'), '', '', 'User'); ?>
%2$s:', menu_page_url('better-analytics', false) . '#top#dimensions', esc_html__('Category Tracking Dimension Index Set', 'better-analytics'));?> ✓✗
%2$s:', menu_page_url('better-analytics', false) . '#top#dimensions', esc_html__('Author Tracking Dimension Index Set', 'better-analytics'));?> ✓✗
%2$s:', menu_page_url('better-analytics', false) . '#top#dimensions', esc_html__('Tag Tracking Dimension Index Set', 'better-analytics'));?> ✓✗
%2$s:', menu_page_url('better-analytics', false) . '#top#dimensions', esc_html__('Publication Year Tracking Dimension Index Set', 'better-analytics'));?> ✓✗
%2$s:', menu_page_url('better-analytics', false) . '#top#dimensions', esc_html__('User Role Tracking Dimension Index Set', 'better-analytics'));?> ✓✗
%2$s:', menu_page_url('better-analytics', false) . '#top#dimensions', esc_html__('Registered User Tracking Dimension Index Set', 'better-analytics'));?> ✓✗
%2$s:', BETTER_ANALYTICS_PRO_PRODUCT_URL . '#utm_source=admin_test&utm_medium=wordpress&utm_campaign=plugin', esc_html__('Better Analytics Pro License', 'better-analytics'));?> ✗
  • ', ''); ?>
  • ', ''); ?>
  • ', ''); ?>
  • ', ''); ?>
  • ', ''); ?>
  • ', ''); ?>
  • ', ''); ?>
  • ', ''); ?>

%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('User-ID Tracking', 'better-analytics'));?>   User-ID%2$s.', 'better-analytics'), '', '');?>
%2$s:', 'https://www.google.com/analytics/web/?#management/Settings/', esc_html__('Demographic and Interest Reports', 'better-analytics'));?>   ', '');?>