【问题标题】:How to add extra query parameters when using the Web Share Target API?使用 Web Share Target API 时如何添加额外的查询参数?
【发布时间】:2019-06-07 13:05:04
【问题描述】:

我有一个使用 Web Share Target API 注册为共享目标的 PWA,我已将以下部分添加到我的清单文件中:

"share_target": {
  "action": "/",
  "method": "GET",
  "enctype": "application/x-www-form-urlencoded",
  "params": {
    "title": "title",
    "text": "text",
    "url": "url"
  }
}

我想使用 Google Analytics 跟踪这些共享,因此我将 utm_sourceutm_medium 参数添加到操作 URL:

"action": "/?utm_source=pwa&utm_medium=share"

经过测试,这些查询参数似乎被titletexturl 替换为params 部分中设置的,而不是附加到URL,所以我们失去了这些初始查询参数。

现在作为一种解决方法,我正在检查查询字符串 window.location.search 是否具有共享参数,并使用 gtag 设置 utm_sourceutm_medium

gtag('set', 'campaign', {source: 'pwa', medium: 'share'});

但我确信有更好的方法来做到这一点。

【问题讨论】:

    标签: progressive-web-apps manifest.json


    【解决方案1】:

    如何将清单更改为

    "action": "/pwa_share/"
    

    并添加您的 .htaccess

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^pwa_share/?(.*)$ /?utm_source=pwa&utm_medium=share&$1 [L]
    

    不能 100% 确定重写规则本身。让我知道它是否有效?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 1970-01-01
      • 1970-01-01
      • 2020-03-22
      • 1970-01-01
      • 2013-07-20
      • 2021-02-03
      相关资源
      最近更新 更多