【问题标题】:Tracking attribution on the WhatsApp Business API?在 WhatsApp Business API 上跟踪归因?
【发布时间】:2019-12-28 07:43:56
【问题描述】:

WhatsApp Business API 没有ref 参数(例如 Messenger 那样),它允许接收应用程序知道给定 WhatsApp 用户来自哪里。

通过 WhatsApp 与企业的对话通常是通过链接发起的 - 可以提供给 wa.me 链接的唯一字段是 numbertext 字段 (source)。

有没有办法绕过这个限制,并在链接中添加一个ref 参数(例如ref=google-ad)?

【问题讨论】:

    标签: whatsapp


    【解决方案1】:

    找到了一个detailed post on encoding params into the WhatsApp link 来解决这个特定的问题。

    没有官方解决方案,但作者有一个聪明的技巧:使用不可打印的字符将 DeviceID(或 ref 参数,在你的情况下)编码为 text 参数。

    编码/解码参数的代码复制如下,但我推荐reading the article了解所有相关细节:

    # This class handles encoding and decoding of non printable characters
    # into strings
    
    class NonPrintableCoder
      NON_PRINTABLES = %W(\u200a \u200b \u200c \u200d \u200e)
    
      class << self
        def encode(num)
          base = NON_PRINTABLES.length
          output = ""
    
          while(num > 0) do
            output = NON_PRINTABLES[num % base] + output # MSB -> LSB
            num /= base
          end
    
          output
        end
    
        def decode(str)
          base = NON_PRINTABLES.length
          output = 0
    
          str.length.times do |i|
            chr = str[str.length - i - 1]
            output += NON_PRINTABLES.index(chr) * base ** i
          end
    
          output
        end
      end
    end
    

    用法:

    # Generate link (encode '12345' into text string)
    "https://wa.me/..?text=" + NonPrintableCoder.encode(12345) + "hi there!"
    
    # Incoming webhook (extract '12345' from text string)
    non_printables = msg.split("").filter do |char|
      char.in? NonPrintableCoder::NON_PRINTABLES
    end
    NonPrintableCoder.decode(non_printables) # => 12345
    

    【讨论】:

      猜你喜欢
      • 2016-12-01
      • 2021-08-16
      • 1970-01-01
      • 2019-10-02
      • 1970-01-01
      • 1970-01-01
      • 2016-04-13
      • 2022-01-22
      • 2022-06-20
      相关资源
      最近更新 更多