Tracking the sources of newly registered account

Re: Tracking the sources of newly registered account

by Michael Milette -
Number of replies: 0
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Abdulhadi,

I have not done that myself however I think you could do this using some custom JavaScript added to the Site Administration > Appearance > Additional HTML page. This would enable it to run on every page load of your Moodle site so that it didn't matter what URL the user comes from or arrives to.

Each time a page on your Moodle site loads, the script would analyze the URL to check if the referrer URL contains the parameter you are looking for. If it finds it, it would save that information to a cookie (or local storage) making it available for use on the registration page.

You will also need a second custom JavaScript, installed the same way, which checks to see if the user is on the registration page. If they are, the script would populate a specific field of the registration form with the information stored in the cookie (or local storage).

So why go through all this when you could just have the script just check the URL of the registration page? Because chances are that the user won't be arriving directly to the registration page. In fact, you would most likely want to refer them to a course page which would lead them to the registration page by which time the special URL parameter would be lost. Even if they arrive on the registration page directly, they could easily decide to browse around your site first (I would). Therefore, it is probably best to capture that special URL parameter from any point of entry.

Now the catch. Whatever URL you point them to, it is important to make sure that Moodle does not automatically redirect the user from that landing page or the JavaScript will not run. Be sure to test extensively as a regular logged in user and a user who is not logged-in.

The example on following page talks about WordPress but it should be possible to use the information as a starting point and adapt some of it for use in Moodle.

https://wordpress.stackexchange.com/questions/221638/referrer-url-with-jquery-or-javascript-cache-referrer-url-issue

You might be find other similar examples by googling for it.

The information on the following page will be useful to check the URL parameters for your special one:

https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams

Note: Depending on your Moodle theme, jQuery may not work so you might also need to convert some of the example code into pure JavaScript.

I wish that I could just give you the code but it is all just conceptual at this point and needs to be developed. Hope you find it helpful.

Best regards,

Michael Milette