Home » Android » java – Transactions keep accumulating in buffer (Google Analytics SDK for Android)

java – Transactions keep accumulating in buffer (Google Analytics SDK for Android)

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying to track downloads and sales of my app with Google Analytics. When my app receives an INSTALL_REFERRER broadcast, it creates a transaction and posts it to GA. However even after a successful dispatch, the transactions still accumulate in the buffer, and are re-sent the next time too (I see this in the debug output of the GA Android SDK).

I am not seeing any new transactions in my GA reports. I’m sure the SDK is reaching the GA servers because there is no network error (if I disable the network I get an exception).

Here is my code:

    // Send this transaction to Google Analytics
    GoogleAnalyticsTracker tracker = GoogleAnalyticsTracker.getInstance();
    tracker.setDebug(true);
    tracker.startNewSession(context.getString(R.string.analytics_account), context);

    // Construct transaction
    String sku = context.getString(R.string.ime_packagename);
    String orderid = Utils.getDeviceID(context) + "-" + sku + "-" + System.currentTimeMillis();
    float price = 1.99f;
    tracker.addTransaction(new Transaction.Builder( 
        orderid,
        price).build());
    tracker.addItem(new Item.Builder(
        orderid,
        sku,
        price,
        1)
    .setItemName(context.getString(R.string.ime_name))
    .build());

     // Dispatch to GA
    tracker.trackTransactions();
    tracker.dispatch();
    // tracker.clearTransactions(); // Uncommenting this line makes no difference!
    tracker.stopSession();

Here is the debug output from the GA SDK for Android. It is dispatching 32 transactions. If I run it again it will dispatch 33 transactions.

01-20 17:34:41.895: D/TypeSmart FREE(1930): Referrer is: utm_source=testing&utm_medium=ref_tracker&utm_campaign=testing
01-20 17:34:41.961: I/GoogleAnalyticsTracker(1930): referrer=utm_source=testing&utm_medium=ref_tracker&utm_campaign=testing
01-20 17:34:42.430: D/GoogleAnalyticsTracker(1930): Referrer store attemped succeeded.
01-20 17:34:42.617: V/GoogleAnalyticsTracker(1930): Called dispatch
01-20 17:34:42.645: I/GoogleAnalyticsTracker(1930): Host: www.google-analytics.com
01-20 17:34:42.645: I/GoogleAnalyticsTracker(1930): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.3.3; en-ca; SGH-I896 Build/GINGERBREAD)
01-20 17:34:42.645: I/GoogleAnalyticsTracker(1930): GET /__utm.gif?utmwv=4.8.1ma&utmn=2117075971&utmt=tran&utmtid=200142206eb49cfd-com.comet.android.TypeSmart&utmtst=&utmtto=&utmttx=&utmtsp=&utmtci=&utmtrg=&utmtco=&utmac=TypeSmart FREE&utmcc=__utma%3D1.1829447487.1327094937.1327094937.1327094937.1%3B&utmht=1327094937149&utmqt=7545496 HTTP/1.1
01-20 17:34:42.649: V/GoogleAnalyticsTracker(1930): Sending 32 hits to dispatcher
01-20 17:34:42.660: D/TypeSmart FREE(1930): Referrer is: utm_source=testing&utm_medium=ref_tracker&utm_campaign=testing
01-20 17:34:42.660: I/GoogleAnalyticsTracker(1930): referrer=utm_source=testing&utm_medium=ref_tracker&utm_campaign=testing
01-20 17:34:42.742: I/GoogleAnalyticsTracker(1930): Host: www.google-analytics.com
01-20 17:34:42.742: I/GoogleAnalyticsTracker(1930): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.3.3; en-ca; SGH-I896 Build/GINGERBREAD)
01-20 17:34:42.742: I/GoogleAnalyticsTracker(1930): GET /__utm.gif?utmwv=4.8.1ma&utmn=101102466&utmt=item&utmtid=200142206eb49cfd-com.comet.android.TypeSmart&utmipc=com.comet.android.TypeSmart&utmipn=TypeSmart%20FREE&utmiva=TypeSmart&utmipr=&utmiqt=1&utmac=TypeSmart FREE&utmcc=__utma%3D1.1829447487.1327094937.1327094937.1327094937.1%3B&utmht=1327094937298&utmqt=7545445 HTTP/1.1
01-20 17:34:42.754: D/GoogleAnalyticsTracker(1930): Referrer store attemped succeeded.
01-20 17:34:42.754: I/GoogleAnalyticsTracker(1930): Host: www.google-analytics.com
01-20 17:34:42.754: I/GoogleAnalyticsTracker(1930): User-Agent: GoogleAnalytics/1.4.2 (Linux; U; Android 2.3.3; en-ca; SGH-I896 Build/GINGERBREAD)
01-20 17:34:42.754: I/GoogleAnalyticsTracker(1930): GET /__utm.gif?utmwv=4.8.1ma&utmn=1136511106&utmt=tran&utmtid=200142206eb49cfd-com.comet.android.TypeSmart&utmtst=&utmtto=&utmttx=&utmtsp=&utmtci=&utmtrg=&utmtco=&utmac=TypeSmart FREE&utmcc=__utma%3D1.1829447487.1327094937.1327094937.1327095148.2%3B&utmht=1327095148884&utmqt=7333867 HTTP/1.1
(31 more dispatches omitted)

UPDATE: I re-installed the app and the problem disappeared. I will try to identify a pattern if it happens again.

How to&Answers: