gglnltcs_print_webproperties

The BestWebSoft Google Analytics gglnltcs print webproperties function.

Description

gglnltcs_print_webproperties( $analytics, (number) $profile_accounts, (number) $accounts_id, $settings ); 

Parameters (4)

0. $analytics
The analytics.
1. $profile_accounts (number)
The profile accounts.
2. $accounts_id (number)
The accounts id.
3. $settings
The settings.

Usage

  1. if ( !function_exists( 'gglnltcs_print_webproperties' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bestwebsoft-google-analytics/bws-google-analytics.php'; 
  3.  
  4. // The analytics. 
  5. $analytics = null; 
  6.  
  7. // The profile accounts. 
  8. $profile_accounts = null; 
  9.  
  10. // The accounts id. 
  11. $accounts_id = null; 
  12.  
  13. // The settings. 
  14. $settings = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = gglnltcs_print_webproperties($analytics, $profile_accounts, $accounts_id, $settings); 
  18.  

Defined (1)

The function is defined in the following location(s).

/bws-google-analytics.php  
  1. function gglnltcs_print_webproperties( $analytics, $profile_accounts, $accounts_id, $settings ) { 
  2. $profile_webproperties = array(); 
  3. /** Web Properties: list 
  4. * https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/webproperties/list */ 
  5. try { 
  6. $output = ''; 
  7. $webproperties = $analytics->management_webproperties->listManagementWebproperties( '~all' ); 
  8. $items = $webproperties->getItems(); 
  9. if ( count( $items ) != 0 ) { 
  10. foreach( $items as $webproperty ) { 
  11. $profile_accounts[ $webproperty->getAccountId() ]['webproperties'][ $webproperty->getId() ] = $webproperty->getName(); 
  12. $profiles = $analytics->management_profiles->listManagementProfiles( $webproperty->getAccountId(), $webproperty->getId() ); 
  13. $profiles_items = $profiles->getItems(); 
  14. if ( count( $profiles_items ) != 0 ) { 
  15. foreach ( $profiles_items as &$profile ) { 
  16. $profile_webproperties[ $webproperty->getId() ] = $profile->getId(); 
  17. } /** close foreach.*/ 
  18. /** get properties of the first account */ 
  19. $first_account = current( $profile_accounts ); 
  20. $first_account_webprops = ''; 
  21. foreach ( $first_account['webproperties'] as $first_account_webprop ) { 
  22. if ( $first_account_webprops == '' ) { 
  23. $first_account_webprops = '<option selected = "selected">' . $first_account_webprop . '</option>' ; 
  24. } else { 
  25. $first_account_webprops .= '<option>' . $first_account_webprop . '</option>' ; 
  26. } ?> 
  27. <tr> 
  28. <th> 
  29. <h3> 
  30. <label for="gglnltcs-webproperties"><?php _e( 'Webproperties', 'gglnltcs' ); ?></label> 
  31. </h3> 
  32. </th> 
  33. <td><!-- Webproperties --> 
  34. <select id="gglnltcs-webproperties" name="gglnltcs_webproperties"> 
  35. <?php echo $first_account_webprops; ?> 
  36. </select> 
  37. <!-- View (Profile) ID --> 
  38. <input id="gglnltcs-view-id" name="gglnltcs_view_id" type="hidden"> 
  39. </td> 
  40. </tr><?php 
  41. $profile_accounts = json_encode( $profile_accounts ); 
  42. $profile_webproperties = json_encode( $profile_webproperties ); 
  43. $accounts_id = json_encode( $accounts_id ); ?> 
  44. <script type="text/javascript"> 
  45. var profileAccounts = <?php echo $profile_accounts; ?>; 
  46. var profileWebproperties = <?php echo $profile_webproperties; ?>; 
  47. var accountsId = <?php echo $accounts_id; ?>;<?php  
  48. if ( isset( $settings['gglnltcs-webproperties'] ) ) { 
  49. $selected_webproperty = json_encode( $settings['gglnltcs_webproperties'] ); ?> 
  50. var selectedWebroperty = <?php echo $selected_webproperty; ?>; 
  51. <?php 
  52. } ?> 
  53. var webPropIDs = []; 
  54. getWebproperties(); 
  55. setViewID(); 
  56. </script><?php 
  57. } /** close if count items.*/ 
  58. } catch ( apiServiceException $e ) { 
  59. echo __( 'There was an Analytics API serviceerror, 'gglnltcs' ) . ' ' . $e->getCode() . ':' . $e->getMessage(); 
  60. } catch ( apiException $e ) { 
  61. echo __( 'There was a general APIerror, 'gglnltcs' ) . ' ' . $e->getCode() . ':' . $e->getMessage();