[javascript] Is it possible to execute multiple _addItem calls asynchronously using Google Analytics?

Would the following code work?

_gaq.push(['_addTrans',     '7171717117', // order ID - required     '',           // affiliation or store name     '2222',       // total - required     '',           // tax     '',           // shipping     '',           // city     '',           // state or province     ''            // country ]); _gaq.push(['_trackTrans']);  _gaq.push(['_addItem',     '7171717117',   // order ID - required     '22j33j2kjk',   // SKU/code - required     'Widget 1.0',   // product name     '',             // category or variation     '2222',         // unit price - required     '1'             // quantity - required ]); _gaq.push(['_trackTrans']); 

This question is related to javascript google-analytics

The answer is

From the docs:

_trackTrans() Sends both the transaction and item data to the Google Analytics server. This method should be called after _trackPageview(), and used in conjunction with the _addItem() and addTrans() methods. It should be called after items and transaction elements have been set up.

So, according to the docs, the items get sent when you call trackTrans(). Until you do, you can add items, but the transaction will not be sent.

Edit: Further reading led me here:


Where it clearly says you can start another transaction with an existing ID. When you commit it, the new items you listed will be added to that transaction.

Questions with javascript tag:

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax Drag and drop menuitems Is it possible to execute multiple _addItem calls asynchronously using Google Analytics? DevTools failed to load SourceMap: Could not load content for chrome-extension TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined raised when starting react app What does 'x packages are looking for funding' mean when running `npm install`? SyntaxError: Cannot use import statement outside a module SameSite warning Chrome 77 "Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6 Why powershell does not run Angular commands? Typescript: No index signature with a parameter of type 'string' was found on type '{ "A": string; } Uncaught Invariant Violation: Too many re-renders. React limits the number of renders to prevent an infinite loop Push method in React Hooks (useState)? JS file gets a net::ERR_ABORTED 404 (Not Found) React Hooks useState() with Object useState set method not reflecting change immediately Can't perform a React state update on an unmounted component UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block Can I set state inside a useEffect hook internal/modules/cjs/loader.js:582 throw err How to post query parameters with Axios? How to use componentWillMount() in React Hooks? React Hook Warnings for async function in useEffect: useEffect function must return a cleanup function or nothing FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory in ionic 3 How can I force component to re-render with hooks in React? What is useState() in React? How to call loading function with React useEffect only once Objects are not valid as a React child. If you meant to render a collection of children, use an array instead How to reload current page? Center content vertically on Vuetify Getting all documents from one collection in Firestore ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment How can I add raw data body to an axios request? Sort Array of object by object field in Angular 6 Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) Axios Delete request with body and headers? Enable CORS in fetch api Vue.js get selected option on @change Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) Angular 6: How to set response type as text while making http call

Questions with google-analytics tag:

Is it possible to execute multiple _addItem calls asynchronously using Google Analytics? 'Linker command failed with exit code 1' when using Google Analytics via CocoaPods No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes PageSpeed Insights 99/100 because of Google Analytics - How can I cache GA? Number of visitors on a specific page How to remove a web site from google analytics Tracking Google Analytics Page Views with AngularJS Best place to insert the Google Analytics code Can you test google analytics on a localhost address? Which browsers support <script async="async" />?