Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jen Brannstrom
Courses Plus Student 5,694 Pointsadding javascript on a Right-to-Left page, error
I am having difficulty with adding some google analytics javascript tag without the code breaking:
The telephone number at the top of this page is hyperlinked for mobile browsers. The header is one div, and contains a Title ("call now" in Hebrew) and the phone number. Possibly because the text next to GA's Click-to-Call tracking is in Hebrew, some browsers get confused. Not mine, but my javascript /google analytics dev's browser. As well as the Google crawlers, and the majority of mobile browsers it seems, because no actual tracking is occurring.
I entered:
<a href="tel:03-771-3027" onclick="_gaq.push(['_trackPageview', '/vpv/clalihtml/header/ClickToCall']);" > 03-771-3027</a>
Instead my dev, GA and AdWords sees:
<a onclick="_gaq.push(['_trackPageview', '/vpv/clalihtml/header/ClickToCall']);" href="tel:03-771-3027"> 03-771-3027</a>
The "href" has gotten swapped with the "onclick" and so no data is fed into GA.
Even though my text editor is set to UTF-8 w/o BOM, line-endings: UNIX, my Chrome browser displays the webpage correctly, yet GA can't parse the tracking code correctly and so nothing registers in GA for my client's mobile AdWords campaign.
Screenshots: 1: my dev's browser 2: my text editor (Notepad++, v5.9.6.2 unicode) 3: my browser, Chrome v. 25
page concerned URL: http://www.concept-academy.co.il/lnd/clali/clali.html
My feeling is that it must also be some UTF-8 issue with my text editor Because switching from RTL (for adding text) to LTR to add code inevitably leaves a trace or hidden characters, line endings, ...something. However, my chrome, FF and IE9 display it correctly, although I have done a lot of work for this client and my Win7 pc may have (somehow) had the right patches installed?
Anyone care to pitch in? Point out the error in my ways??
4 Answers
Mark Flavin
10,199 PointsIt works fine for me but that could be anything from browser to os differences. You might get better success by using the jQuery Click api and as your function calling the gaq.push code you wanted to access.
<a class="tel" href="tel:03-771-3027" > 03-771-3027</a>
$('.tel').click(function () {
_gaq.push(['_trackPageview', '/vpv/clalihtml/header/ClickToCall']);
});
Jen Brannstrom
Courses Plus Student 5,694 PointsThanks for your advice Mark! I confess my jQuery skills are mediocre at best, would you mind checking out this attempt on a test domain:?
Mark Flavin
10,199 PointsYou need to move your script after you load jQuery.
Jen Brannstrom
Courses Plus Student 5,694 PointsHi Mark, Thanks for that, I did that change, and I believe it is ok now. test domain:.
Is there a way to see if it actually gets triggered? I tried it a few times on my mobile, but nothing is showing up in Google Analytics. Even after 24 hours. I thought this could be because I have deployed it to a test domain, (as in this hack, but I have set no such filter yet) instead of the intended domain that the GA account is for, yet when I try the Real-Time feature in GA, it shows me visiting after a few seconds.
I suppose, worst case scenario I deploy to the live site. There is nothing to lose really, as the clicktocall-tracking isn't working anyway right now, and we've switched off the campaign in AdWords targeting mobile.
I tried Google'ing the problem but this is over my head
Any thoughts? Many thanks in advance!