How to use Enhanced E-Commerce via API

1,414 views
Skip to first unread message

Liam Ma

unread,
Jul 3, 2014, 2:04:59 AM7/3/14
to google-analytics-m...@googlegroups.com
Hi Developers,

I am using PHP to post data to 'https://ssl.google-analytics.com/collect' via Curl,

the pay load is below,

[
'v' => 1,
'tid' => 'UA-52479722-1',
'cid' => '555',
't' => 'item',
'ti' => '12345',
'pr[1]nm' => 'test1',
'pr[1]pr' => '2.00',
'pr[1]qt' => '2',
'pr[1]id' => 'u3eqds44',
'pr[1]ca' => 'furniture',
'pr[2]nm' => 'test2',
'pr[2]pr' => '2.00',
'pr[2]qt' => '2',
'pr[2]id' => 'u3eqds45',
'pr[2]ca' => 'furniture',
'pa' => 'purchase'
]

However, it's not appear in the google analtyics, just wondering what the correct format of sending data like Product Name(pr[\d+]nm=Android%20T-Shirt) 

Thank you!

Hugo Marques

unread,
Jul 3, 2014, 6:13:30 PM7/3/14
to google-analytics-m...@googlegroups.com
Hello

Anyone knows a link thatg explains with sample code how we can use the  Enhanced  Ecommerce with Measurement Protocol?

If i want send multiple products how it works? I only see the parameter pr[\d+]nm without any index. If i send for instance 2 productItems and if i use the same parameter (pr[\d+]nm) for both how google analytics knows wich one have the quantity 1 and quantity 2 for instance?

Thanks

HUGO

Vincent Enjalbert

unread,
Jul 8, 2014, 2:26:45 PM7/8/14
to google-analytics-m...@googlegroups.com
Same Issue here.

However, I'm using this format :


[
'v' => 1,
'tid' => 'UA-52479722-1',
'cid' => '555',
't' => 'item',
'ti' => '12345',
'pr1nm' => 'test1',
'pr1pr' => '2.00',
'pr1qt' => '2',
'pr1id' => 'u3eqds44',
'pr1ca' => 'furniture',
'pr2nm' => 'test2',
'pr2pr' => '2.00',
'pr2qt' => '2',
'pr2id' => 'u3eqds45',
'pr2ca' => 'furniture',
'pa' => 'purchase'
]

Vincent Enjalbert

unread,
Jul 8, 2014, 2:31:10 PM7/8/14
to google-analytics-m...@googlegroups.com
Oh, 

And I'm using an event to send the purchase action :

 [v] => 1

    [tid] => UA-4XXXX-1

    [cid] => 651XXX375

    [t] => event

    [ec] => sales

    [ea] => transaction

    [el] => paid

    [ev] => 70.8

    [ni] => 1

    [pa] => purchase

    [ti] => 300000193-197

    [ta] => 

    [tr] => 70.8

    [ts] => 0.0000

    [tt] => 11.8

    [cu] => EUR

    [pr1id] => PID

    [pr1nm] => PName

    [pr1ca] => Cat

    [pr1br] => 

    [pr1va] => 

    [pr1pr] => 59.0000

    [pr1qt] => 1

Vincent Enjalbert

unread,
Jul 10, 2014, 5:28:57 AM7/10/14
to google-analytics-m...@googlegroups.com
Well I still can't get this work.

I tried :

    [v] => 1

    [tid] => UA-52697451-1

    [cid] => 12345

    [t] => transaction

    [ti] => 20140710091702

    [ta] =>

    [tr] => 10

    [ts] => 1

    [tt] => 1

    [cu] => EUR

    [pa] => purchase

    [tcc] => coupon_test

    [ni] => 1

    [pr1id] => test

    [pr1nm] => produit test

    [pr1ca] => category

    [pr1br] => brand

    [pr1va] =>

    [pr1pr] => 9

    [pr1qt] => 1


=> Transaction is registered, but not the item.


I also tried with two calls :

    [v] => 1

    [tid] => UA-52697451-1

    [cid] => 12345

    [t] => transaction

    [ti] => 20140710090817

    [ta] =>

    [tr] => 10

    [ts] => 1

    [tt] => 1

    [cu] => EUR

    [pa] => purchase

    [tcc] => coupon_test

    [ni] => 1


AND


    [v] => 1

    [tid] => UA-52697451-1

    [cid] => 12345

    [t] => item

    [ti] => 20140710090817

    [cu] => EUR

    [pa] => purchase

    [pr1id] => test

    [pr1nm] => produit test

    [pr1ca] => category

    [pr1br] => brand

    [pr1va] =>

    [pr1pr] => 9

    [pr1qt] => 1

    [ni] => 1


=> Idem..

Is someone succeed to make this work ? 


Liam Ma

unread,
Jul 11, 2014, 2:34:16 AM7/11/14
to google-analytics-m...@googlegroups.com
Hi Vincent

I believe you need to make  [t] => event instead of transaction. The documentation of measurement protocol is extremely poor, however the documentation of Analytics.js is good: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference

I recommend you test it with Analytics.js, and inspect the network via your browser debug tool, and see how javascript handles it. See my attached screenshot. The fields used on javascript side are exactly same as measurement protocol.

Hope it helps.
Screen Shot 2014-07-11 at 4.03.09 pm.png

Vincent Enjalbert

unread,
Sep 12, 2014, 10:46:01 AM9/12/14
to google-analytics-m...@googlegroups.com
Hello Liam,

I've just seen your answer. Sorry for the late reply, but yes you was right twice : Documentation is poor, and it is was waiting an event!

Everything is working since then, but the partial refunds. Have you succeed with that ?

Andy Granowitz

unread,
Sep 12, 2014, 1:26:56 PM9/12/14
to google-analytics-m...@googlegroups.com
That's correct, you must send Enhanced Ecommerce data with another hit type, like an Event. You can see some examples on how to send Enhanced Ecommerce with the Measurement Protocol here: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#enhancedecom

Liam, about the partial refunds, it looks like you've filed this in the issue tracker. For others on the thread, look there for updates: https://code.google.com/p/analytics-issues/issues/detail?id=491

-Andy 

Andres Hinostroza

unread,
May 20, 2015, 12:54:39 PM5/20/15
to google-analytics-m...@googlegroups.com
Vincent, 

I'm experiencing the same problem. I noticed on 7/8/14  you wrote that you were sending the hit via t=event but it wasn't working. Then later on 9/12/14 you said that it was waiting for an event and it finally worked. So I'm confused by your latest reply since it seemed you initially had used the event hit type.  I'm trying to understand what you changed from your example provided on 7/8/14 to your latest reply on 9/12/14 confirming it worked.

We have tried both t=event and t=pageview to send enhanced ecommerce data but it's not registering. The debug tool returns no error. 

Your feedback is much appreciated!

Vincent Enjalbert

unread,
May 20, 2015, 1:17:09 PM5/20/15
to google-analytics-m...@googlegroups.com
Hello Andres,

I don't remember, but the data from my message fon 7/8/14 seems correct.

Show us your data, we'll perhaps be able to help.

Ivica Cvetković

unread,
Jun 10, 2015, 9:24:08 AM6/10/15
to google-analytics-m...@googlegroups.com
Hi Vincent,

regardless to Andreas question and data we're sending, we use 2 curl calls, one for transaction and other for item(s). 

Here's data we're sending for transaction:

v=1
tid
=**********
cid
=14213442-c222-4cdf-9a23-cb9f269c10da
t
=transaction
ti
=9999
tr
=1959.2000
tt
=0
ts
=0
cd1
=33100


and other for item:
v=1
tid
=*************
cid
=14213442-c222-4cdf-9a23-cb9f269c10da
t
=event
ec
=Offline
ea
=Sale
el
=Paid
ev
=1959
ni
=1
ti
=9999
tr
=1959.2000
tt
=0
ts
=0
pa
=purchase
pr1id
=4014
pr1nm
=Redmon+Sofa+%28Custom%29
pr1ca
=Sofas
pr1br
=Joybird+Furniture
pr1va
=DL%2CWalnut
pr1pr
=1959.2
pr1qt
=1
cd1
=33100

Basically very similar to what you did on 7/10/14 (with 2 curl calls).
Google tester tool reported no errors, but when we checked Google Analytics data, it was showing 0 items for transaction.
It's very strange that sometimes very similar data we send is reported in GA correctly.

Thanks for help in advance


Reply all
Reply to author
Forward
0 new messages