This is a follow-up of #1981320: Incompatibility with ga_push

ga_push already provides the functionality to send push events to GA. It has the following function and seems to be doing exactly doing what we need even with an example for GA commerce tracking:

<?php
/**
 * API for other modules to call in order to add events to the queue.
 *
 * @param push (Array)
 * push parameters.
 * Structure:
 *
 * EVENT:
 *  array(
 *    'Videos',              //Category,
 *    'Play',                //Action',
 *    'Gone With the Wind' , //Label,
 *    1,                     //'Value (Numeric)'
 *  );
 *
 * ECOMMERCE:
 *  array(
 *    'trans' => array(
 *      '1234',           // order ID - required
 *      'Acme Clothing',  // affiliation or store name
 *      '11.99',          // total - required
 *      '1.29',           // tax
 *      '5',              // shipping
 *      'San Jose',       // city
 *      'California',     // state or province
 *      'USA'             // country
 *    ),
 *    'items' => array(
 *      array(
 *        '1234',         // order ID - required
 *        'DD44',         // SKU/code - required
 *        'T-Shirt',      // product name
 *        'Green Medium', // category or variation
 *        '11.99',        // unit price - required
 *        '1'             // quantity - required
 *      ),
 *    ),
 *  )
 *
 *
 * @param type String
 * The GA PUsh type: Event, Ecommerce... Use the defined constants
 * @param method_key String
 * The method identificator
 */
function ga_push_add($push, $type = GA_PUSH_TYPE_EVENT, $method_key = NULL)
?>

And is documented like this:

Comments

cyberschorsch’s picture

Assigned: Unassigned » cyberschorsch

I am taking a deeper look into this now. If everything goes well I will release a second dev branch with the implementation soon.

luksak’s picture

Status: Active » Needs review

Just did a quick and dirty patch for this. I tested it quickly and the tracking code looks ok:

<script>var _gaq = _gaq || [];
_gaq.push(['_addTrans', '575', 'Online Shop', '56', '0', '0', 'Zürich', '', 'Switzerland']);
 _gaq.push(['_addItem', '575', '130', 'Productname', 'No category', '56', '1.00']);
 _gaq.push(['_addItem', '575', 'shipping', 'Free shipping', 'No category', '0', '1.00']);
 _gaq.push(['_trackTrans']);
 </script>

But the data is not being tracked. Since I have a issue with tracking the Ecommerce data to GA in general (#1987920: Data not tracked to GA), this doesn't mean that my patch isn't working. Can someone please test it?

luksak’s picture

StatusFileSize
new3.44 KB

And here comes the patch :)

gedur’s picture

As the issue #1984858 says: http://drupal.org/node/1984858 the next ga_push parameters have been changed to an associative array, currently on dev branch. This will be on the stable branch next week.

<?php
/**
 * API for other modules to call in order to add events to the queue.
 *
 * @param push (Array)
 * push parameters.
 * Structure:
 *
 * EVENT:
 *  array(
 *    'category'        => 'Videos',              // (required) The name you supply for the group of objects you want to track.
 *    'action'          => 'Play',                // (required) A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
 *    'label'           => 'Gone With the Wind',  // (optional) An optional string to provide additional dimensions to the event data.
 *    'value'           => 1,                     // (optional) An integer that you can use to provide numerical data about the user event.
 *    'non-interaction' => false,                 // (optional) A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation.
 *  );
 *
 * ECOMMERCE:
 *  array(
 *    'trans' => array(
 *      'order_id' => '1234',           // order ID - required
 *      'affiliation' => 'Acme Clothing',  // affiliation or store name
 *      'total' => '11.99',          // total - required
 *      'total_tax' => '1.29',           // tax
 *      'total_shipping' => '5',              // shipping
 *      'city' => 'San Jose',       // city
 *      'region' => 'California',     // state or province
 *      'country' => 'USA'             // country
 *    ),
 *    'items' => array(
 *      array(
 *        'order_id' => '1234',         // order ID - required
 *        'sku' => 'DD44',         // SKU/code - required
 *        'name' => 'T-Shirt',      // product name
 *        'category' => 'Green Medium', // category
 *        'price' => '11.99',        // unit price - required
 *        'quantity' => '1'             // quantity - required
 *      ),
 *    ),
 *  )
 *
 *
 * @param type String
 * The GA PUsh type: Event, Ecommerce... Use the defined constants
 * @param method_key String
 * The method identificator
 */
function ga_push_add($push, $type = GA_PUSH_TYPE_EVENT, $method_key = NULL)
?>
luksak’s picture

StatusFileSize
new3.07 KB

Damn... I was even thinking that it was very ugly code that I am writing and I even looked at the latest commit messages of ga_push :) anyways... here is the much nicer fixed patch.

luksak’s picture

StatusFileSize
new3.05 KB

Forgot to remove one dsm().

cyberschorsch’s picture

Status: Needs review » Active

I just created a new dev Release which uses the ga_push module as new api for sending the transactions. When available to download, please test this version and make new issues for each error with the new version as tag.

luksak’s picture

So this is fixed?

cyberschorsch’s picture

I would suggest to mark this as fixed when we release Version 2.0

gedur’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new3.23 KB

Hi Cyberschorsch!
In the current 7.x-2.x branch the commerce_google_analytics_build_push_array() there are missing the items (line_items) params, only the transaction is being returned and some keys are not named properly.

Attaching a patch that includes it.

Anonymous’s picture

I also noticed keys were not named properly - patch in #10 works for me with regards to matching up the field names.

Anonymous’s picture

Status: Needs review » Needs work

Actually just noticed you changed one "qty" to "quantity" but missed the one on line 122:

'qty' => $line_item->quantity->value()

gedur’s picture

Status: Needs work » Needs review
StatusFileSize
new3.24 KB

Thanks stevepurkiss! Attaching a new patch with "quantity" key.

Anonymous’s picture

Thanks, tested & works fine - #13 looks good to go to me.

cyberschorsch’s picture

Status: Needs review » Needs work

Thank you both for working on this.

The patch needs a little bit of work. Please check if it applys to the coding standards (see whitespaces).

gedur’s picture

Checked the *.module file with: https://drupal.org/project/coder : Drupal CodeSniffer, Drupal Coding Standards, Drupal Commenting Standards, Drupal SQL Standards, Drupal Security Checks.

No errors found, if you find one just tell me to generate a new patch. There some coding standard issues on the other files but I think this should be on a different issue or patch.

gedur’s picture

Status: Needs work » Needs review

Needs review

cyberschorsch’s picture

Status: Needs review » Closed (fixed)

Thank you guys for fixing this. I will close this ticket. For new issues, please open a new ticket in the issue queue.