Updated: Comment #4

Problem/Motivation

Google Analytics custom fields are defined in the Google Analytics Views module as a single field, using '(n)' to represent the variable part of the field. The module doesn't provide a mechanism for specifying which variation of the custom field you want to use. Therefore, if a custom field is used, the query will contain fields with this '(n)' place holder text which causes the query to fail.

Proposed resolution

The initial proposed solution was to manually specify all custom field variations. This is impractical as Google Analytics Premium accounts allow up to fifty variations of each custom field and there are currently 9 custom fields. This would add 450 fields to views while failing to account for the possiblity of new custom fields or more than fifty variations.

Instead of manually specifying all custom field variations, configuration forms should provide an integer text field allowing users to specify the variation to use.

Remaining tasks

  1. Review the latest patch
  2. Commit

User interface changes

Adds a new integer text field to configuration forms of custom fields for specifying which variation to use.

Original report by q2_faith

ga:customVarValue(n) in fields, views don't show result.
In Query Explorer I wrote ga:customVarValue1 to get the result. How can I do in views(ga:customVarValue1 instead of ga:customVarValue(n))

Comments

q2_faith’s picture

Component:Views» Reports module

as a temporary solution
in google_analytics_views.module instead

<?php
'customVarValue(n)' =>
  array(
   
'type' => 'dimension',
   
'group' => 'Custom Variables',
   
'name' => 'ga:customVarValue(n)',
   
'description' => 'The value for the requested custom variable.',
  ),
?>

I made 5 fields, foreach custom variable
for example

<?php
'customVarValue1' =>
  array(
   
'type' => 'dimension',
   
'group' => 'Custom Variables',
   
'name' => 'ga:customVarValue1',
   
'description' => 'The value for the requested custom variable.',
  ),
...
?>
jtbayly’s picture

Status:Active» Needs review

Yep, I originally put this comment up on the views integration issue, but I' moving it here.

Google Analytics allows for tracking custom variables, and the Google Analytics module also supports this. However, I wasn't able to query those custom variables with Views. They can only be referenced by number (1-5).

So I took a quick look, and the change is quite simple.

In google_analytics_views.module, we simply need to put 5 options for customvar that specify the number instead of one that doesn't. So this code needs to change:

  'customVarName(n)' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName(n)',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue(n)' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue(n)',
    'description' => 'The value for the requested custom variable.',
  ),

Here is what it should be instead:

  'customVarName1' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName1',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue1' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue1',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName2' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName2',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue2' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue2',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName3' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName3',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue3' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue3',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName4' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName4',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue4' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue4',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName5' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName5',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue5' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue5',
    'description' => 'The value for the requested custom variable.',
  ),

Sorry, I don't really know how to create a proper patch. But I tested this, and I was able to query those custom variables just fine after I made the change .

-Joseph

mastermindg’s picture

This is just to verify that the above change to google_analytics_views.module has worked for me.

jantoine’s picture

Title:Views don't work with custom variables» Views break when custom fields are used
Component:Reports module» Views module
Issue summary:View changes
StatusFileSize
new16.38 KB

Attached patch does the following:

  • Adds a base google_analytics_handler_filter views handler
  • Renames the google_analytics_handler_field_string views handler to google_analytics_handler_field as nothing was string specific
  • Renames the google_analytics_handler_argument_string views handler to google_analytics_handler_argument as nothing was string specific
  • Enhances all views handlers to properly handle custom fields by:
    • Offering a "custom field number" integer field on configuration forms
    • Converting a base custom field to a specific custom field before adding the field to the query
    • Converting a specific custom field to a base custom field when checking if the field is available
  • Adds the google_analytics_views_is_custom() function for determining if a google analytics field is a custom field or not
  • Adds the google_analytics_views_custom_to_variable_field() function for converting a base custom field name and a number into a specific custom field
  • Adds the google_analytics_views_variable_to_custom_field() function for converting a specific field name into a base custom field name
  • Updates the google_analytics_handler_filter_numeric and google_analytics_handler_filter_string views handlers to extend the google_analytics_handler_filter views handler.
mikelangeloff’s picture

#2

Your solution is good, the only this is that you don't have to replace anything, just add it after:

  'customVarName(n)' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName(n)',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue(n)' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue(n)',
    'description' => 'The value for the requested custom variable.',
  ),
'customVarName1' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName1',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue1' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue1',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName2' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName2',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue2' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue2',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName3' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName3',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue3' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue3',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName4' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName4',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue4' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue4',
    'description' => 'The value for the requested custom variable.',
  ),
  'customVarName5' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarName5',
    'description' => 'The name for the requested custom variable.',
  ),
  'customVarValue5' =>
  array(
    'type' => 'dimension',
    'group' => 'Custom Variables',
    'name' => 'ga:customVarValue5',
    'description' => 'The value for the requested custom variable.',
  ),

Otherwise, the view won't build it correctly, and you won't get any results.

;)

jtbayly’s picture

Hmm.. It worked at the time. Maybe something has changed. Regardless, the way you've got it certainly looks like it would work just as well to me. But did you try the patch in #4? Just curious, cause it would be nice to get it committed if it works.

-Joseph

mikelangeloff’s picture

I did, but it didn't do the trick for me. :(

jtbayly’s picture

Status:Needs review» Needs work

(See above, where mikelangeloff says the patch didn't work for him.)

Greg Boggs’s picture

I just enabled the patch in #4 and it works perfectly for me. If mike had trouble, perhaps it was user error in building the view.

Greg Boggs’s picture

Category:Bug report» Feature request
Status:Needs work» Needs review

  • Plazik committed 77217c5 on 7.x-3.x authored by jantoine
    Issue #1649270 by jantoine | q2_faith: Fixed Views break when custom...
Plazik’s picture

Category:Feature request» Bug report
Status:Needs review» Fixed
Parent issue:» #2357771: META: Plan for Google Analytics Reports 7.x-3.0-beta1 release

Patch from #4 commited.

Plazik’s picture

Status:Fixed» Needs work
Plazik’s picture

Status:Needs work» Fixed

Status:Fixed» Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.