/    Sign up×
Community /Pin to ProfileBookmark

google ecommerce javascript doesn’t work

i need some help with google ecommerce javascript code. As google shows an example of how to implement this function in a website it works fine. But here’s the problem: i need to send data to analytics when asp.net button is pressed, so appropriate way to achieve that is to write javascript function, and place it before </head> tag. here’s the code:

[CODE]<script type=”text/javascript”>
function sendAnalytics(){

var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-27232165-1’]);
_gaq.push([‘_trackPageview’]);
_gaq.push([‘_addTrans’,
‘1334’, // order ID – required
‘Clothing’, // affiliation or store name
‘11.99’, // total – required
‘1.29’, // tax
‘5’, // shipping
‘San Jose’, // city
‘California’, // state or province
‘USA’ // country
]);

// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each
_gaq.push([‘_addItem’,
‘1334’, // order ID – required
‘DDD4’, // SKU/code – required
‘T-bag’, // product name
‘Green Medium’, // category or variation
‘11.99’, // unit price – required
‘1’ // quantity – required
]);
_gaq.push([‘_trackTrans’]); //submits transaction to the Analytics servers

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();
return true;
}
</script>[/CODE]

on button click function sendAnalytics() is invoked, but it seems that this part of code doesn’t work, because analytics doesn’t receive any data.

[CODE] (function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})(); [/CODE]

any suggestions? Thank you in advance for your help

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @kiladm spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...