How to get E-commerce transaction ID from Google Analytics tracker

985 Views Asked by At

I'd like to know how to get the E-commerce transaction ID from a Google Analytics tracker object.

I already found the tracker.get() method: https://developers.google.com/analytics/devguides/collection/analyticsjs/accessing-trackers

By using tracker.get('clientId'), I successfully obtained the client ID from the Analytics tracker object.

According to the Analytics debug log, there is some transaction data stored in the Analytics tracker object with 'ec:id' as the transaction ID field. I tried to obtain the value of this field by using tracker.get('ec:id'), but this didn't return any result.

Analytics debug log

2

There are 2 best solutions below

2
Matvey Andreyev On

Inspect your tracker in the console. The following checks the first tracker, for example:

ga.getAll()[0];

Inspect the data field, then inspect the keys field. It'll be an array of what you can pass to a tracker's .get() method.

I suggest you try getting the _ti out of your tracker:

ga.getAll()[0].get('_ti');

If it corresponds with the transaction ID, then I did not screw up.

0
XTOTHEL On

You should be able to reference the parameter by itself by using the ampersand syntax. Documentation

Reference for field parameters

So for your case:

tracker.get('&ti')