Startseite / Promoting the Partner in the Digital Lifecycle with Acquia Insight

Promoting the Partner in the Digital Lifecycle with Acquia Insight

As a Solutions Architect for Channel Enablement, I spend a good deal of my time thinking about how to better integrate our delivery partners in the digital lifecycle of client sites deployed on the Acquia platform. The vast majority of our partners have their own “secret sauce” in the form of knowledge, best practice, and process spanning the gamut of the digital experience: search engine optimization, marketing campaign analytics, mobile and responsive design, content and UX strategy, and much more. This value-add is captured at the time of delivery, but remains even more important to continuously monitor and improve the site experience. Acquia Insight is a tool that partners can use today-- for the low price of free-- to deliver this value-add in real-time and feature their own services.

Custom Insight test

In this blog post, I will walk through how to leverage Acquia Insight in a scenario that should hopefully be familiar to every delivery partner. A client site has been developed and tested against major browsers at the time of delivery. The client is thrilled with the results (natch!), but over time newly introduced browser versions and ever evolving mobile devices create digital entropy. The site may not be displayed properly and the client would not even know. What can we do to help the client get a better experience? Let’s write a custom Insight test to compare Google Analytics browser data against a list of validated user agent patterns. If new browser versions are detected, an alert in the Insight dashboard will suggest to contact the partner.

Setting up

In this example, you will need access to a Acquia Cloud subscription with the site connected to Acquia Network. You will also need to check out the git repository on your local machine (Acquia Dev Desktop is recommended).

If you are working with a brand new site:

  1. Create an Acquia Cloud Free subscription and after the site is provisioned, select Install Drupal from the Dev server drop down menu.
  2. Select the Acquia Drupal install profile and after the code is deployed, visit and configure the site. The site will be automatically connected to your subscription; you can leave the subscription ID and key blank.
  3. Add your public key to access the git repository.

If you are working with a site already on Acquia Cloud:

  1. If the site is not already connected to Acquia Network, download and configure the module Acquia Network Connector.
  2. Confirm your public key to access the git repository.

Once the site is installed on the Dev server, pull the code to your local environment. If you need help with this step, consult the online documentation on using Acquia Dev Dektop or checking out the repo. From the local code base, create the following two directories if they do not already exist.

$ cd /path/to/local/docroot
$ mkdir sites/all/modules/contrib
$ mkdir sites/all/modules/custom

 

Create the module scaffold

Start out by creating a scaffold for the custom module. It is Drupal standard practice to place downloaded community modules in sites/all/modules/contrib and any custom modules in sites/all/modules/custom. Create a new directory partner_insight for our module.

$ cd /path/to/local/docroot
$ mkdir sites/all/modules/custom/partner_insight

Every Drupal module requires .info and .module files. In partner_insight.info, meta information about the module is added, such as the dependency to the Acquia Site Profile Information module.

... ... @@ -0,0 +1,7 @@
  1 +name = Partner Insight
  2 +description = Use Acquia Insight to embed the delivery partner into the digital lifecycle of the site.
  3 +package = Acquia Network Connector
  4 +core = 7.x
  5 +version = "7.x-alpha"
  6 +
  7 +dependencies[] = acquia_spi

In partner_insight.module, hook_acquia_spi_test() is implemented with a callback to perform the test and return a boolean.

... ... @@ -0,0 +1,41 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @file
  5 + * Use Acquia Insight to embed the delivery partner into the digital lifecycle
  6 + * of the site.
  7 + *
  8 + * @author: John Money <john.money@acquia.com>
  9 + */
  10 +
  11 +define('PARTNER_INSIGHT_GA_UA_FIX_ACTION', 'Contact Digital Agency to schedule a consultation.');
  12 +
  13 +/**
  14 + * Implements hook_acquia_spi_test().
  15 + * Defines custom Acquia Insight tests. Each test must have a unique key.
  16 + *
  17 + * @see acquia_connector/acquia_spi/acquia_spi.api.php for more information.
  18 + */
  19 +function partner_insight_acquia_spi_test() {
  20 + return array(
  21 + 'partner_insight_ga_ua' => array(
  22 + 'description' => 'Your theme was tested for compatibility against major browsers at the time of site delivery. However, newly introduced browser versions may result in the site not being displayed properly.',
  23 + 'solved_message' => 'Theme has been browser tested.',
  24 + 'failed_message' => 'Theme has not been tested for all browsers.',
  25 + 'solved' => _partner_insight_ga_ua(),
  26 + 'fix_details' => 'PARTNER_INSIGHT_GA_UA_FIX_ACTION',
  27 + 'category' => 'best_practices', // Possible values: performance, security, best_practices
  28 + 'severity' => 1, // Possible values: 0, 1, 2, 4, 8, 16, 32, 64, 128
  29 + ),
  30 + );
  31 +}
  32 +
  33 +/**
  34 + * Callback from partner_insight_acquia_spi_test().
  35 + *
  36 + * @return boolean
  37 + * TRUE if all user agents have already been tested.
  38 + */
  39 +function _partner_insight_ga_ua() {
  40 + return FALSE;
  41 +}

Commit and push these changes up to your Acquia Cloud repo.

$ git add sites/all/modules/custom/partner_insight
$ git commit -m"initial scaffold"
$ git push

 

Verify your Insight test

SSH to your Acquia Cloud dev server, enable the Partner Insight module, and verify the test is properly formed. I am assuming your subscription is named mysite; make sure to substitute your own. You could use the Drupal administration interface for many of these tasks, but using Drush is significantly faster so I will reference that method throughout.

$ drush @mysite.dev en -y partner_insight
$ drush @mysite.dev spi-tv
Acquia SPI custom tests were detected in: partner_insight

[PASSED] Validation passed for 'partner_insight.'

Validation checks completed.
1 module(s) passed validation: partner_insight.

Insight tests run with cron and sends data to Acquia Network once every 30 minutes. You should be able to confirm the time of the last data update from the Insight tab in your Acquia Cloud workflow. See the failed message that was configured partner_insight_acquia_spi_test()? Great, it’s working! Let’s begin to flesh out the rest of the logic of the module:

Custom Insight test
  • Google Analytics (GA) will be used to collect visitor browser information and the site will be configured to send data
  • Google Analytics API will be used to retrieve browser statistics and the site will be authorized to access account
  • Delivery partner will configure user agent patterns for tested browsers in an administrative form
  • Insight test will compare browser information against user agent patterns

Configure Google Analytics

Create a GA account for this site if you do not already have one, and note the tracking ID. Download the module Google Analytics and commit to your Acquia Cloud repo. (Drush is automatically installed with Acquia Dev Desktop on the Mac. For Windows users, you have a few more steps to get it working in your local environment.)

$ cd /path/to/local/docroot
$ drush dl google_analytics
$ git add sites/all/modules/contrib/google_analytics
$ git commit -m"import google_analytics"

In partner_insight.info, add a dependency to the Google Analytics module.

@@ -5,3 +5,4 @@ core = 7.x
5 5 version = "7.x-alpha"
6 6
7 7 dependencies[] = acquia_spi
  8 +dependencies[] = googleanalytics

A Drupal module can implement hooks in an .install file when the module is enabled, updated, or uninstalled. In partner_insight.install, we will add an install requirement for the GA module to be configured.

... ... @@ -0,0 +1,27 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @file
  5 + * Installation file for Partner Insight module.
  6 + */
  7 +
  8 +/**
  9 + * Implements hook_requirements().
  10 + */
  11 +function partner_insight_requirements($phase) {
  12 + $requirements = array();
  13 + $t = get_t();
  14 +
  15 + if ($phase == 'install') {
  16 + // Google Analytics must be configured.
  17 + if (!preg_match('/^UA-\d{4,}-\d+$/', variable_get('googleanalytics_account', 'UA-'))) {
  18 + $requirements['googleanalytics'] = array(
  19 + 'description' => $t('Google Analytics module has not been configured. <a href="/de/%40url">Configure Google Analytics</a>.', array('@url' => url('admin/config/system/googleanalytics'))),
  20 + 'severity' => REQUIREMENT_ERROR,
  21 + 'value' => '',
  22 + );
  23 + }
  24 + }
  25 +
  26 + return $requirements;
  27 +}

Commit these changes to your Acquia Cloud repo and push.

$ git add sites/all/modules/custom/partner_insight
$ git commit -m"add dependency google_analytics"
$ git push

SSH to your Acquia Cloud dev server, enable the Google Analytics module, and configure with the site tracking ID. There are other potentially interesting GA settings available at admin/config/system/googleanalytics, but are not required.

$ drush @mysite.dev en -y googleanalytics
$ drush @mysite.dev vset googleanalytics_account UA-YOUR_TRACKING_ID

Google Analytics should now be connected to your site and collecting data. You can verify this by examining the source code of your home page and searching for _gaq.push(["_setAccount". You can also seed some initial user agent data by using a browser screenshot or testing service like BrowserStack or Browserling.

Configure Google Analytics API

Download the modules Google Analytics Reports and OAuth and commit to your Acquia Cloud repo. We will only be using two submodules from these packages to enable API integration.

$ cd /path/to/local/docroot
$ drush dl google_analytics_reports
$ git add sites/all/modules/contrib/google_analytics_reports
$ git commit -m"import google_analytics_reports"

$ drush dl oauth
$ git add sites/all/modules/contrib/oauth
$ git commit -m"import oauth"

In partner_insight.info, add a dependency to the Google Analytics Reports module.

@@ -6,3 +6,4 @@ version = "7.x-alpha"
6 6
7 7 dependencies[] = acquia_spi
8 8 dependencies[] = googleanalytics
  9 +dependencies[] = google_analytics_api

In partner_insight.install, modify the function partner_insight_requirements() to add an install requirement for the GA Reports module to be configured.

@@ -21,6 +21,15 @@ function partner_insight_requirements($phase) {
21 21 'value' => '',
22 22 );
23 23 }
  24 +
  25 + // Google Analytics API must be configured.
  26 + if (!variable_get('google_analytics_reports_profile_id', 0)) {
  27 + $requirements['google_analytics_reports'] = array(
  28 + 'description' => $t('Google Analytics API module has not been configured. <a href="/de/%40url">Configure Google Analytics API</a>.', array('@url' => url('admin/config/system/google-analytics-reports'))),
  29 + 'severity' => REQUIREMENT_ERROR,
  30 + 'value' => '',
  31 + );
  32 + }
24 33 }
25 34
26 35 return $requirements;

Commit these changes to your Acquia Cloud repo and push.

$ git add sites/all/modules/custom/partner_insight
$ git commit -m"add dependency google_analytics_reports"
$ git push

SSH to your Acquia Cloud dev server, enable the modules OAuth Common and Google Analytics API.

$ drush @mysite.dev en -y oauth_common googleanalytics_api

Go to the Google Analytics Reports administration page at admin/config/system/google-analytics-reports to authorize access to your Google Analytics account. Click the button Start Setup and Authorize Account. You will be redirected to Google allow access and then back to your site. If you have more than one site profile associated with the Google Analytics account, select the profile from the Google Analytics Reports administration page and click Save settings.

Add administration form

Partners will need to be able to configure which user agents have already been tested, so we will need an administration form to store this as a system variable. In partner_insight.module, register a new system path with the hook_menu function.

@@ -11,6 +11,22 @@
11 11 define('PARTNER_INSIGHT_GA_UA_FIX_ACTION', 'Contact Digital Agency to schedule a consultation.');
12 12
13 13 /**
  14 + * Implements hook_menu().
  15 + */
  16 +function partner_insight_menu() {
  17 + $items['admin/config/system/partner-insight'] = array(
  18 + 'title' => 'Partner Insight',
  19 + 'description' => 'Configure Partner Insight.',
  20 + 'page callback' => 'drupal_get_form',
  21 + 'page arguments' => array('partner_insight_admin'),
  22 + 'access arguments' => array('administer site configuration'),
  23 + 'file' => 'partner_insight.pages.inc',
  24 + );
  25 +
  26 + return $items;
  27 +}
  28 +
  29 +/**
14 30 * Implements hook_acquia_spi_test().
15 31 * Defines custom Acquia Insight tests. Each test must have a unique key.
16 32 *

This path calls a form defined in partner_insight_admin, which is located in a new file partner_insight.pages.inc. We perform some minor validation on the user input and convert the non-empty strings into an array.

... ... @@ -0,0 +1,51 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @file
  5 + * Partner Insight configuration page.
  6 + */
  7 +
  8 +/**
  9 + * Menu callback for admin settings.
  10 + */
  11 +function partner_insight_admin() {
  12 + $form = array();
  13 +
  14 + $form['partner_insight_ua_regex'] = array(
  15 + '#type' => 'textarea',
  16 + '#title' => 'User agent patterns',
  17 + '#description' => 'Add a regex pattern for each tested user agent string on a separate line. Do not include delimiters in the pattern.',
  18 + '#default_value' => implode("\n", variable_get('partner_insight_ua_regex', array('unknown'))),
  19 + '#required' => TRUE,
  20 + );
  21 +
  22 + return system_settings_form($form);
  23 +}
  24 +
  25 +/**
  26 + * Validation function for admin settings. Valid regex is converted to array
  27 + * pre-save with form_set_value.
  28 + */
  29 +function partner_insight_admin_validate($form, &$form_state) {
  30 + if (!empty($form_state['values']['partner_insight_ua_regex'])) {
  31 + $valid_regex = array();
  32 + $regex_strings = explode("\n", $form_state['values']['partner_insight_ua_regex']);
  33 +
  34 + foreach ($regex_strings as $regex) {
  35 + $regex = trim($regex);
  36 + if (!empty($regex)) {
  37 + $valid_regex[] = $regex;
  38 + }
  39 + }
  40 +
  41 + if (!empty($valid_regex)) {
  42 + form_set_value($form['partner_insight_ua_regex'], $valid_regex, $form_state);
  43 +
  44 + // Invalidate previously cached result.
  45 + _partner_insight_set_result_cache();
  46 + }
  47 + else {
  48 + form_set_error('partner_insight_ua_regex', 'User agent patterns field is required.');
  49 + }
  50 + }
  51 +}

Note that the internal function _partner_insight_set_result_cache() is called during validation and will be defined in the next section. As a best practice, the module should remove any system variables that it set when uninstalled in partner_insight.install.

@@ -34,3 +34,10 @@ function partner_insight_requirements($phase) {
34 34
35 35 return $requirements;
36 36 }
  37 +
  38 +/**
  39 + * Implements hook_uninstall().
  40 + */
  41 +function partner_insight_uninstall() {
  42 + variable_del('partner_insight_ua_regex');
  43 +}

Finally, register the module configuration path in partner_insight.info which gets displayed on the modules listing.

@@ -3,6 +3,7 @@ description = Use Acquia Insight to embed the delivery partner into the digital
3 3 package = Acquia Network Connector
4 4 core = 7.x
5 5 version = "7.x-alpha"
  6 +configure = admin/config/system/partner-insight
6 7
7 8 dependencies[] = acquia_spi
8 9 dependencies[] = googleanalytics

Commit these changes to your Acquia Cloud repo.

$ git add sites/all/modules/custom/partner_insight
$ git commit -m"add administration config"

 

Retrieve data from GA

Ah, behold the power of Drupal. The Google Analytics API has already been abstracted into a module by the community, so our function to retrieve data from GA consists mostly of massaging the data and caching the results.

@@ -55,3 +55,27 @@ function partner_insight_acquia_spi_test() {
55 55 function _partner_insight_ga_ua() {
56 56 return FALSE;
57 57 }
  58 +
  59 +/**
  60 + * Retrieve user agent data from Google Analytics.
  61 + */
  62 +function _partner_insight_get_ua_data() {
  63 + $cid = 'partner_insight:ga_ua';
  64 + $ua_data = array();
  65 +
  66 + // Data is cached based on settings from GA API. The Google Analytics Quota
  67 + // Policy restricts the number of queries made per day.
  68 + if ($cache = cache_get($cid)) {
  69 + $ua_data = $cache->data;
  70 + }
  71 + else {
  72 + // Query Google Analytics API.
  73 + // @see https://developers.google.com/analytics/devguides/reporting/core/v3/refe...
  74 + $params = array(
  75 + 'metrics' => array('ga:sessions'),
  76 + 'dimensions' => array('ga:operatingSystem,ga:browser,ga:browserVersion'),
  77 + 'start_date' => strtotime('-30 days'),
  78 + 'end_date' => strtotime('today'),
  79 + 'sort_metric' => array('-ga:sessions'),
  80 + );
  81 + $query = google_analytics_api_report_data($params);

We will clean up the data with a recursive callback to _partner_insight_ua_text, extract a major version from the browser version reported, and calculate the percent of total sessions this browser represents.

@@ -79,3 +79,21 @@ function _partner_insight_get_ua_data() {
79 79 'sort_metric' => array('-ga:sessions'),
80 80 );
81 81 $query = google_analytics_api_report_data($params);
  82 +
  83 + // Process results.
  84 + if (!empty($query->results)) {
  85 + foreach ($query->results as $ua) {
  86 + $ua = array_map('_partner_insight_ua_text', $ua);
  87 +
  88 + // Determine major version from browserVersion.
  89 + preg_match('/[0-9]+/', $ua['browserVersion'], $match);
  90 + $majorVersion = !empty($match[0]) ? $match[0] : 'unknown';
  91 +
  92 + // Determine percent of total sessions.
  93 + $percentTotal = round(100 * $ua['sessions'] / $query->totals['sessions']);
  94 +
  95 + $ua_data[] = array(
  96 + 'ua' => $ua['browser'] . ',' . $majorVersion . ',' . $ua['operatingSystem'] . ',' . $ua['browserVersion'],
  97 + 'pct' => $percentTotal,
  98 + );
  99 + }

Finally, the GA data is cached to limit the number of API calls and the result cache is emptied so that it must be recalculated. The main data retrieval function is complete.

@@ -97,3 +97,13 @@ function _partner_insight_get_ua_data() {
97 97 'pct' => $percentTotal,
98 98 );
99 99 }
  100 +
  101 + // Set data cache.
  102 + cache_set($cid, $ua_data, 'cache', time() + variable_get('google_analytics_reports_cache_length', 259200));
  103 + // Invalidate result cache.
  104 + _partner_insight_set_result_cache();
  105 + }
  106 + }
  107 +
  108 + return $ua_data;
  109 +}

Two private functions previously referenced also need to be added.

@@ -107,3 +107,20 @@ function _partner_insight_get_ua_data() {
107 107
108 108 return $ua_data;
109 109 }
  110 +
  111 +/**
  112 + * Helper function to set result cache. Note that this can be called with no
  113 + * argument to invalidate the cache.
  114 + */
  115 +function _partner_insight_set_result_cache($result = array()) {
  116 + $cid = 'partner_insight:ga_ua_result';
  117 + $expire = !empty($result) ? CACHE_PERMANENT : CACHE_TEMPORARY;
  118 + cache_set($cid, $result, 'cache', $expire);
  119 +}
  120 +
  121 +/**
  122 + * Helper function to remove special characters from string.
  123 + */
  124 +function _partner_insight_ua_text($str) {
  125 + return check_plain(str_replace(',', '', $str));
  126 +}

Commit these changes to your Acquia Cloud repo.

$ git add sites/all/modules/custom/partner_insight
$ git commit -m"add GA data retrieval"

 

Modify the test to actually test

We’re nearly at the finish line. All the pieces are in place to make the test actually test. In the initial scaffolding, we hardcoded the description, fix_details and severity. Let’s replace that with something more dynamic by calling the same function as solved, but with arguments.

@@ -35,13 +35,13 @@ function partner_insight_menu() {
35 35 function partner_insight_acquia_spi_test() {
36 36 return array(
37 37 'partner_insight_ga_ua' => array(
38   - 'description' => 'Your theme was tested for compatibility against major browsers at the time of site delivery. However, newly introduced browser versions may result in the site not being displayed properly.',
  38 + 'description' => _partner_insight_ga_ua('description'),
39 39 'solved_message' => 'Theme has been browser tested.',
40 40 'failed_message' => 'Theme has not been tested for all browsers.',
41 41 'solved' => _partner_insight_ga_ua(),
42   - 'fix_details' => 'PARTNER_INSIGHT_GA_UA_FIX_ACTION',
  42 + 'fix_details' => _partner_insight_ga_ua('fix_details'),
43 43 'category' => 'best_practices', // Possible values: performance, security, best_practices
44   - 'severity' => 1, // Possible values: 0, 1, 2, 4, 8, 16, 32, 64, 128
  44 + 'severity' => _partner_insight_ga_ua('severity'), // Possible values: 0, 1, 2, 4, 8, 16, 32, 64, 128
45 45 ),
46 46 );
47 47 }

The callback function will now need to accept an argument and uses a static variable to return the result based on the argument as it will be called multiple times. We also implement caching of the result which can be invalidated when new GA data is retrieved or the user agent patterns are modified.

@@ -52,9 +52,26 @@ function partner_insight_acquia_spi_test() {
52 52 * @return boolean
53 53 * TRUE if all user agents have already been tested.
54 54 */
55   -function _partner_insight_ga_ua() {
56   - return FALSE;
57   -}
  55 +function _partner_insight_ga_ua($type = 'solved') {
  56 + static $result;
  57 +
  58 + if (!isset($result)) {
  59 + $cid = 'partner_insight:ga_ua_result';
  60 +
  61 + // Get result cache.
  62 + if ($cache = cache_get($cid)) {
  63 + if (!empty($cache->data)) {
  64 + $result = $cache->data;
  65 + }
  66 + }
  67 +
  68 + // Result may still be empty if cache was invalidated.
  69 + if (empty($result)) {
  70 + // Get Google Analytics data.
  71 + $ua_data = _partner_insight_get_ua_data();
  72 +
  73 + // Get UA regex patterns.
  74 + $ua_regex = variable_get('partner_insight_ua_regex', array('unknown'));
58 75
59 76 /**
60 77 * Retrieve user agent data from Google Analytics.

The default result will be success.

@@ -73,6 +73,16 @@ function _partner_insight_ga_ua($type = 'solved') {
73 73 // Get UA regex patterns.
74 74 $ua_regex = variable_get('partner_insight_ua_regex', array('unknown'));
75 75
  76 + // Set default (no action required).
  77 + $result = array(
  78 + 'description' => t('Your theme was tested for compatibility against major browsers at the time of site delivery. Based on Google Analytics visitor data from the past 30 days, no new browser versions have been found. Huzzah!'),
  79 + 'solved' => TRUE,
  80 + 'severity' => 1,
  81 + 'fix_details' => t('No action required.'),
  82 + );
  83 + $ua_untested = array();
  84 + $ua_untested_percent = 0;
  85 +
76 86 /**
77 87 * Retrieve user agent data from Google Analytics.
78 88 */

The core functionality of the test is a loop through the GA user agent strings, running each regex pattern against a string until a pattern match is found.

@@ -83,6 +83,27 @@ function _partner_insight_ga_ua($type = 'solved') {
83 83 $ua_untested = array();
84 84 $ua_untested_percent = 0;
85 85
  86 + // Iterate over each ua.
  87 + foreach ($ua_data as $ua) {
  88 + $found = FALSE;
  89 +
  90 + // Iterate over each regex pattern.
  91 + foreach ($ua_regex as $regex) {
  92 + @preg_match('/' .$regex. '/', $ua['ua'], $match);
  93 + // Found one, no need to continue.
  94 + if (!empty($match[0])) {
  95 + $found = TRUE;
  96 + break;
  97 + }
  98 + }
  99 +
  100 + // Store not found and increment percent.
  101 + if (!$found) {
  102 + $ua_untested[] = $ua['ua'] . ' (' .$ua['pct']. '%)';
  103 + $ua_untested_percent += $ua['pct'];
  104 + }
  105 + }
  106 +
86 107 /**
87 108 * Retrieve user agent data from Google Analytics.
88 109 */

If any user agent strings are in the untested array, alter the result to fail.

@@ -104,6 +104,20 @@ function _partner_insight_ga_ua($type = 'solved') {
104 104 }
105 105 }
106 106
  107 + // Found one or more ua that failed regex.
  108 + if (!empty($ua_untested)) {
  109 + // Percent cannot exceed 100 (rounding effect).
  110 + if ($ua_untested_percent > 100) $ua_untested_percent = 100;
  111 +
  112 + $result = array(
  113 + 'description' => t('Your theme was tested for compatibility against major browsers at the time of site delivery. Based on Google Analytics visitor data from the past 30 days, @percent% of sessions are from versions of browsers that have not yet been tested and may result in the site not being displayed properly.', array('@percent' => $ua_untested_percent)) . ' ' . t('The top three untested browsers are:') . ' ' . implode(' - ', array_slice($ua_untested, 0, 3)),
  114 + 'solved' => FALSE,
  115 + 'severity' => _partner_insight_severity_from_total($ua_untested_percent),
  116 + 'fix_details' => PARTNER_INSIGHT_GA_UA_FIX_ACTION,
  117 + 'ua' => $ua_untested,
  118 + );
  119 + }
  120 +
107 121 /**
108 122 * Retrieve user agent data from Google Analytics.
109 123 */

Finally, cache the result and return the result argument.

@@ -118,6 +118,14 @@ function _partner_insight_ga_ua($type = 'solved') {
118 118 );
119 119 }
120 120
  121 + // Set result cache.
  122 + _partner_insight_set_result_cache($result);
  123 + }
  124 + }
  125 +
  126 + return $result[$type];
  127 +}
  128 +
121 129 /**
122 130 * Retrieve user agent data from Google Analytics.
123 131 */

Add the function to convert the percent of untested user agents into an escalating severity level.

@@ -194,3 +194,22 @@ function _partner_insight_set_result_cache($result = array()) {
194 194 function _partner_insight_ua_text($str) {
195 195 return check_plain(str_replace(',', '', $str));
196 196 }
  197 +
  198 +/**
  199 + * Helper function to convert 0-100 percent to Insight severity level.
  200 + */
  201 +function _partner_insight_severity_from_total($percent) {
  202 + if ($percent > 85) {
  203 + return 64;
  204 + }
  205 + if ($percent > 60) {
  206 + return 32;
  207 + }
  208 + if ($percent > 40) {
  209 + return 16;
  210 + }
  211 + if ($percent > 20) {
  212 + return 8;
  213 + }
  214 + return 4;
  215 +}

Commit and push these changes to your Acquia Cloud repo. Ship it, we’re done.

$ git add sites/all/modules/custom/partner_insight
$ git commit -m"add Insight test"
$ git push

 

Partners in the Digital Lifecycle

I hope this example on browser monitoring and theme testing resonates as a real world opportunity to integrate into the digital lifecycle of client sites. The full code with additional help is available on Github for you to use and modify to better meet your needs. And it is only one of many possibilities for partners to leverage Acquia Insight. If you implement your own custom Insight tests with client sites, please leave a comment or drop me a line. I’d love to hear how Acquia Insight was leveraged to better serve our customers and our partners as the subject of a future blog post.

Neuen Kommentar schreiben

Plain text

  • Keine HTML-Tags erlaubt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • HTML - Zeilenumbrüche und Absätze werden automatisch erzeugt.

Filtered HTML

  • Use [acphone_sales], [acphone_sales_text], [acphone_support], [acphone_international], [acphone_devcloud], [acphone_extra1] and [acphone_extra2] as placeholders for Acquia phone numbers. Add class "acquia-phones-link" to wrapper element to make number a link.
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <h4> <h5> <h2> <img>
  • HTML - Zeilenumbrüche und Absätze werden automatisch erzeugt.
By submitting this form, you accept the Mollom privacy policy.