Using multiple jquery libraries for GA scroll tracking


Hi,

I’ve asked this question in support but didn’t get a satisfactory response. No offence to the support of course, it’s not like all unbounce support staff should know jquery.

I’m trying to track scroll events on my unbounce pages which requires jquery 1.7. I’ve been told to disable the default jquery 1.4 by unbounce staff as it would cause a conflict but there are 2 jquery’s used on unbounce, an additional jquery is used for the unbounce app itself so it can’t be disabled.

My question is what’s the point of disabling one of them when there’s another to still cause a conflict. If the unbounce app jquery can be used without causing a conflict can’t I just do the same with the other one? If so how do I do this.

I notice the noconflict is used in the source code how could I do the same for the jquery 1.7 I need to use.

Many thanks


7 replies

Userlevel 2

We do include a version of jQuery on all pages, to handle form submissions and the like. However, it’s namespaced to lp.jQuery , meaning it can’t conflict with any other versions of jQuery you include on your page Ð whether that’s through enabling the 1.4.2 option, or manually adding a newer version.

Here’s some background on how this works, if you’re interested: http://api.jquery.com/jquery.noconflict/

Disabling our version 1.4.2 is definitely the easiest way to avoid conflicts. This will allow you to include your own version and able to use the $ variable without worrying about conflicts.

Does anyone else here in the community have any experience with using newer versions of jQuery in Unbounce?

Hi Jev,

Good question, the reason why you want to disable the 1.4 version of jQuery is exactly the reason you mentioned in that it would cause a conflict. You are correct that we are including our version of jQuery (also version 1.4) but the reason this does not matter to you is because we have put it into “no-conflict” mode. http://api.jquery.com/jquery.noconflict/

This allows us to use jQuery without the worry that it will interfere with any javascript library you use. Now, if you use jQuery in conflict mode and you include another jQuery library or any library like prototype.js this will be ripe for all sorts of weird errors.

This is why we recommend unchecking the jquery checkbox if you want to use another version of jQuery that way you don’t need to worry about having any conflicts.

Kind Regards,

Slan

Thanks Mark & Slan for your answers.

Unbounce staff have actually added some code for me to use the 1.7 version with the tracking so if I did use the no conflict code Mark suggested after referencing the 1.7 version, would I have to change all instances of $ in their code?

Thanks

Thanks Mark & Slan for your answers.

Unbounce staff have actually added some code for me to use the 1.7 version with the tracking so if I did use the no conflict code Mark suggested after referencing the 1.7 version, would I have to change all instances of $ in their code?

Thanks

Thanks Mark,

I’ve had a thought, can I just tap into the jQuery you guys already use by using your variable reference?

So for example before I turned the jQuery off I used this code to use fancybox

$("a[href$='.jpg'],a[href$='.png'],a[href$='.gif']").attr('rel', 'gallery').fancybox();

Since switching it off can I access the behind the scenes jQuery using the following?

lp("a[href$='.jpg'],a[href$='.png'],a[href$='.gif']").attr('rel', 'gallery').fancybox();

Thanks

Userlevel 2

Hi Danny,

Yes, you could (with lp.jQuery , not just lp ) Ð but since that’s 1.4.2 as well, I’m not sure what that would achieve.

The bottom line is this: if you need to use a newer version of jQuery, simply uncheck the jQuery checkbox in the page builder, add a ```

 tag to include the newer version and then just feel free to use 

$

 throughout your scripts. <br /><br /> Thanks!</script>

Hi Mark,

The problem is I’ve already used 1.4.2 to create scroll effects and use fancybox before I wanted to add the tracking code so I’m trying to keep those effects as well as adding the 1.7 I need for the scroll depth.

I would rather get fancybox etc. to work with 1.7 but I’m not sure what changes would need to be made and it’s not worth a day of reading to find out. What it achieves is that the lp.jquery version has already been put into noConflict mode. Unbounce staff added the GA code for 1.7 and I don’t want to mess their work up by trying to put it into noConflict mode.

Thanks for your help

Reply