Answer the question
In order to leave comments, you need to log in
How to create events on the site using utm tags?
Hello! Not strong in js, but I will be grateful if you at least orient in which direction to start looking.
The following is required: depending on the parameters of utm tags, I should have a certain event on the site, for example, a person clicked on a certain tag through contextual advertising, and, accordingly, the function corresponding to this tag was executed.
Answer the question
In order to leave comments, you need to log in
See what's in location
and run the desired piece of code.
----------------
You can write a function to get the label:
function getUTM(name){
var target = location.search.match(
new RegExp("utm_"+name+"=([^&]+)")
);
return target ? target[1] : null;
}
switch(getUTM("source")){
case "yandex": //Делаем что-то
break;
case "google": //Или делаем это
break;
}
var funcGen = {
"yandex" : function(){ ... },
"google" : function(){ ... }
}[getUTM("source")];
//Если есть такая - запустим
funcGen&&funcGen();
utm-tag is essentially a get-parameter.
catch the value of the get-parameter (more conveniently through PHP, not through js) and execute the code you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question