How to add Javascript to Wix pages

Hi there. Is there a way that I can add Javascript to my Wix pages? The Javascript I have will be used to store parameters in my tracking template urls, and then pass them in links leading away from my site.

  1. The first javascript on the landing page will grab these parameters from the URL of the browser and save them to a cookie.
  2. The second javascript will retrieve these values from the cookie and then append all the tracking links on that page with the affiliate_id, source and aff_sub parameters as required.

So I have the codes, I just don’t know where and how to add them to my site. Any help gratefully received!

Thanks

Tim

You can use wix storage and the local for saving permanent cookies in the users local storage. Read more at the API page about storage and local.

Hi Tim,
Check out this article .
Like Andreas said, you can use Wix Storage .
Feel free to paste your code here
Roi

Thanks guys

These are the instructions I received on the code that needs adding:

Sample Code
The following code requires js-cookie available from https://github.com/js-cookie/js-cookie
Script to get parameters from the URL and save them to a cookie

Script to get parameters from cookies and add them to all tracking links

It looks like since this post was put up, that Wix have made it so much easier to add javascript to websites. Whether that be custom (as appears to be the case in this thread, or more standard (e.g. adding Google Analytics), Wix have come up with the goods to make it possible. Have never posted here before (so unsure on the rules) but we’ve done a 11 step guide on how to add javascript, which will hopefully be useful to people - How to add javascript to Wix websites - A1WebStats

seems only an upgraded (pay) site has these functions

Hi @getrajbose !

Thats actually not true,
these features are open to all users regardless to their paid plan.
I advise you to check out the article that Roi shared.

Doron.

Hi Doron Alkalay
Option is disabled.
It requries to upgrade plan.

My site is upgraded, however, when I try to insert my Javascript snippet via the custom tracking tools, nothing happens. Granted, it’s not a tracking tool, we’re trying to embed a webcam feed. I’ve set up a hidden page to test this, and when I check the page, it’s absolutely blank. I’ve tried it in all three available locations: head, body start, and body ed. Any advice from anyone? This is one of three webcam feeds we’re trying to insert.

            <script> 

TIMEOUT = 750;
errorcounter = 0;
var refreshInterval;
$(document).ready(function() {
// Active camera will refresh every 2 seconds
refreshInterval = setInterval(function() {
var random = Math.floor(Math.random() * Math.pow(2, 31));
$(‘img#camera’).attr(‘src’, ‘http://107.170.210.163:3000/camera?i=’ + Math.random());
}, TIMEOUT);
});
function imgError(image) {
image.src = “http://www.fourpawsdaycare.com/wp-content/uploads/2015/12/404camera.gif”;

return true; 

}

Hi,

I’m trying to track events with Mixpanel, using the code mixpanel.track(“event”); but I’m getting the error message: ‘mixpanel’ is not defined.

I know that I need to import mixpanel but I can’t find where to import it from.

I’ll appreciate your help,
Asaf

Hi, I know this is an old thread but I wonder if someone can help me. I’m trying to inject javascript with the 11 step method described. I need to add the javascript only to the blog pages. The problem is that the individual blogs are not listed as actual pages because Wix pulls the content of the blogs from a database and generates the blog on the fly. Looking at the browser address box I can see that the actual URL of any particular blog is https://www.mywebsitename.com/post/post-title but like I said earlier, these pages are not listed in the pulldown where you can select specific pages (step 9).
Any ideas on how can I implement that ? Thank you !

I’m having the same thing happen, I add the code and nothing happens in preview. It’s a simple crypto coin price chart.


  <script type="text/javascript">
baseUrl = "https://widgets.cryptocompare.com/";
var scripts = document.getElementsByTagName("script");
var embedder = scripts[ scripts.length - 1 ];
var cccTheme = {"General":{"borderColor":"#0b4d82"},"Header":{"background":"#0b4d82","color":"#fff200","displayFollowers":false},"Chart":{"fillColor":"#68d4ff","borderColor":"#2a0ebf"}};
(function (){
var appName = encodeURIComponent(window.location.hostname);
if(appName==""){appName="local";}
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
var theUrl = baseUrl+'serve/v1/coin/chart?fsym=BTC&tsym=USD';
s.src = theUrl + ( theUrl.indexOf("?") >= 0 ? "&" : "?") + "app=" + appName;
embedder.parentNode.appendChild(s);
})();
</script>

You’ll have to use an iframe and use postMessage to replace DOM elements like window.location.hostname and baseUrl

https://www.wix.com/corvid/reference/$w.HtmlComponent.html#postMessage

As of this writing, you have to have a premium site to add code through the Wix site editor. Here is my work-around to add Facebook page like button - can be used for other code as well. I used Facebook Code generator ( https://developers.facebook.com/docs/plugins/like-button/# ) then created a page on my site that is hidden from the menu and hidden from SEO, pasted the first code into HTML iframe on this hidden page, then pasted the second code (iframe code, for the button itself) on the page where I wanted the button. Make sure the HTML box (iframe) is large enough so the sliders are not visible so there are no sliders on your visible site.

No need for a premium account to add code to a Wix web site. You just need to enable dev mode .

@yisrael-wix Thank you! I enabled Dev Mode (easy), but still does not give me access to Tracking Tools and Analytics so I can add code. Any suggestions appreciated. Wix should make their help articles so that non-programmers can follow them. :slight_smile:

@kevinandmarsha Aha - now I know what you were referring to. You are correct that Tracking and Analytics requires a premium account in order to connect a domain.

@yisrael-wix Thank you. Is there another way to add code to a free Wix site, such as for Facebook button, and EcWid stores?

What are you trying to do with your code as note that you can already add EcWid without using code as shown here.
https://support.wix.com/en/article/third-party-app-online-store-by-ecwid
https://support.ecwid.com/hc/en-us/articles/115005874885-Adding-your-Ecwid-store-to-Wix-site
https://support.ecwid.com/hc/en-us/articles/207808335-Ecwid-plans-and-pricing-for-Wix

The same with Facebook, you can do various bits for it without using code, like you have mentioned in your post - add Facebook page like button.
https://support.wix.com/en/article/using-facebook-on-your-wix-site
https://support.wix.com/en/article/adding-and-setting-up-a-facebook-like-button
https://support.wix.com/en/article/adding-and-setting-up-a-facebook-share-button
https://support.wix.com/en/article/facebook-like-button-vs-facebook-page-like-box

Also, note that this post is originally from 2018 and you are much better adding a new post rather than bumping up an old post and referring back to this old post in a link, otherwise the post could be closed.