简体   繁体   English

将 UTM 参数传递到网页内容中

[英]passing UTM parameters into a web-page content

I am using a tracking software (Voluum) that generates for me campaign URLs with UTM parameters.我正在使用一个跟踪软件 (Voluum),它为我生成带有 UTM 参数的活动 URL。 Is there a way how I could pass the data from my UTM parameters and display it as a dynamic content on a web-page?有没有办法从我的 UTM 参数中传递数据并将其作为动态内容显示在网页上?

For example a visitor accesses domain.com/?city={city} where the {city} in his case is Berlin .例如,访问者访问domain.com/?city={city}其中{city}在他的例子中是Berlin is it possible to show him the word "Berlin" on the web-page right during his first visit?是否可以在他第一次访问时在网页上显示“柏林”这个词?

thank you!谢谢你!

You have several ways to do this:你有几种方法可以做到这一点:

  1. On the server side , if your server supports PHP, Python... or any server side language that can dynamically服务器端,如果您的服务器支持 PHP、Python... 或任何可以动态运行的服务器端语言

In PHP you can retrieve the variable using the $_GET array.在 PHP 中,您可以使用 $_GET 数组检索变量。

$_GET['city']
  1. On the client side , using JavaScript客户端,使用 JavaScript

Here is a function that retrieves the variable 'name' from the URL这是从 URL 检索变量“名称”的 function

function getURLParameter(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

You can use it like that:你可以这样使用它:

document.write(getURLParameter('city'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM