javascript - Google Analytics AJAX e-commerce tracking -


I have an index.html which introduces the Universal Google Analytics tracking code:

 < Code> & lt; Script & gt; (Function (I, S, O, G, R, A, M) {i ['GoogleAnalyticsObject'] = R; I [R] = I [R] || function () {(I [R]. C = I [r] .q || []). Push (argument)}, I [R] .L = 1 * New date (); a = s.create element (O), M = S. ElementElementBitagname (O) [0]; a.async = 1; a.src = g; m.parentNode.insertBefore (a, m)}) (window, document, 'script', '// www.google-analytics.com/analytics. Js', 'ga'); GA ('Create', 'UA-XXXXXXX-X', 'Auto'); Ga ('Send', 'Pageview'); & Lt; / Script & gt;   

Later I load an HTML document which I insert through AJAX. Can I put JavaScript code for e-commerce tracking in a script tag in HTML which I insert again via Ajax without launching Google Analytics again? So I would have something like this:

HTML inserted through AJAX:

    

Will this be tracked correctly? And if a visitor closes the page or navigates, then is it likely that Javascript is not being executed?

On this issue, I give more hints about how I should be capable.

Thanks in advance!

Generate ecommerce code in Ajax script and launch the page on the page.

This works but maybe there is some disturbance with it and I do not pay attention to it. :)

Overall it will look like this:


gener_ecommerce_data.php:
    

On the calling page:

  & lt; Script & gt; (Function (I, S, O, G, R, A, M) {i ['GoogleAnalyticsObject'] = R; I [R] = I [R] || function () {(I [R]. C = I [r] .q || []). Push (logic)}, I [R] .l = 1 * new date (); a = s.create element (o), m = s.getElementsByTagName (o) [0]; a.async = 1; a.src = g; m.parentNode.insertBefore (a, m)}) (window, document, 'script', '// google-analytics.com/analytics.js' , 'Ga'); GA ('Create', 'UA-UANUMBER', 'Nomenclature'); GA ('Requirement', 'ECC'); Click $ ('# Element') (function () {$ .ajax ({type: 'POST', url: '/ajax/generate_ecommerce_data.php', success: function (response) {$ ('# container') .HTML ('& lt; script & gt;' + feedback + '& lt; \ / script & gt;'); ga ('send', 'pageview'); $ ('# container'). ');}, Error: function (error) {console.log (err.status);}});}); & Lt; / Script & gt;   

PS: It looks like I'm over the message limit and it is necessary to trim the Ajax code, but you can get this idea.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -