Reputation: 3
Any suggestions as to why this dynamic value will not report report in GA?
To start:
I have created a way to split the URL parameters up so that I can insert the value from the URL that I want into the Google Analytics event onclick tracking.
This is an example of my URL:
<http://www.example.org/sweden/se/stod-oss/gava/info/?view=DDM&price=118>
The price in the url is a dynamic amount.
This is how I successfully split the url up in the :
<script type="text/javascript">
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');
for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
}
}
</script>
So that works correctly and when I insert params.price into the button submit it works fine wen placed in the category section, like so:
<button type="submit" onClick="_gaq.push(['SE._trackEvent', 'se_donationpages', 'submitinfo', params.price,, false])" class="btn btn-gp btn-gp-special">Next<i class="icon-arrow-right icon-white"></i></button>
Google Analytics registers this fine in the reports.
But, this is not where I want this. I would like the price value to be inserted in the value section, like so:
<button type="submit" onClick="_gaq.push(['SE._trackEvent', 'se_donationpages', 'submitinfo', 'payment',params.price, false])" class="btn btn-gp btn-gp-special">Nästa <i class="icon-arrow-right icon-white"></i></button>
So, when I do this one above, Google Analytics does not register the event at all.
I thought there might be a problem with the value being a string, so I converted the price parameter to a integer like so in the head:
<script type="text/javascript">
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');
for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
}
}
var price_param = params.price;
var view_param = params.view;
var price_param_int = parseInt(price_param)
</script>
and inserted the variable into the button code like so:
<button type="submit" onClick="_gaq.push(['SE._trackEvent', 'se_donationpages', 'submitinfo', 'payment',price_param_int, false])" class="btn btn-gp btn-gp-special">Next<i class="icon-arrow-right icon-white"></i></button>
...but, this doesnt report in GA :(
Any suggestions as to why this dynamic value will not report report in GA?
It's boggling my mind!
Upvotes: 0
Views: 1009
Reputation: 32517
You are right that it must be an integer variable type. I don't know why GA doesn't just convert it automatically..
perhaps you simply typoed while posting, but in your code, you assign the integer-converted value to price_param_int
(notice the lack of "s" on "param") but in your GA code you reference price_params_int
edit
Okay you mentioned in comment that it was just a typo when posting.. well I tested your code and it works fine. So here's another dumb question: are you sure you are going to your page with the price
parameter actually in the URL? e.g.
http://www.yoursite.com/page.html?price=123
If you are and it's still not working then.. you must have something else going on that's affecting your code, because when I just have on a test page GA code and that button and the query param grabbing code you posted, it works fine.
Upvotes: 1