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
Comment #1
cyberschorschI am taking a deeper look into this now. If everything goes well I will release a second dev branch with the implementation soon.
Comment #2
luksakJust did a quick and dirty patch for this. I tested it quickly and the tracking code looks ok:
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?
Comment #3
luksakAnd here comes the patch :)
Comment #4
gedur commentedAs 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.
Comment #5
luksakDamn... 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.
Comment #6
luksakForgot to remove one dsm().
Comment #7
cyberschorschI 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.
Comment #8
luksakSo this is fixed?
Comment #9
cyberschorschI would suggest to mark this as fixed when we release Version 2.0
Comment #10
gedur commentedHi 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.
Comment #11
Anonymous (not verified) commentedI also noticed keys were not named properly - patch in #10 works for me with regards to matching up the field names.
Comment #12
Anonymous (not verified) commentedActually just noticed you changed one "qty" to "quantity" but missed the one on line 122:
'qty' => $line_item->quantity->value()Comment #13
gedur commentedThanks stevepurkiss! Attaching a new patch with "quantity" key.
Comment #14
Anonymous (not verified) commentedThanks, tested & works fine - #13 looks good to go to me.
Comment #15
cyberschorschThank 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).
Comment #16
gedur commentedChecked 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.
Comment #17
gedur commentedNeeds review
Comment #18
cyberschorschThank you guys for fixing this. I will close this ticket. For new issues, please open a new ticket in the issue queue.