ampproject / amphtml

The AMP web component framework.
https://amp.dev
Apache License 2.0
14.89k stars 3.89k forks source link

Overwriting ampdocUrl in Google Analytics/amp-analytics not working #1742

Closed ryanlombardo closed 8 years ago

ryanlombardo commented 8 years ago

Setting a custom value for ampdocUrl does not override the default value being sent to in the Google Analytics request.

By default, Google Analytics sends the AMP url and we want to change it to the canonical url.

Here's our config:

  <script type="application/json">
    {
      "vars": {
        "account": "{{Analytics.google_analytics_id}}"
      },
      "requests": {
        "pageviewWithCD27": "${pageview}&cd27=${cd27}"
      },
      "triggers": {
        "trackPageviewWithCustom": {
          "on": "visible",
          "request": "pageviewWithCD27",
          "vars": {
            "ampdocUrl": "CANONICAL_URL",
            "cd27": "amp"
          }
        }
      }
    }
  </script>

And here's the request sent to GA showing the default value still being used. (Look for the dl parameter.)

https://www.google-analytics.com/r/collect?v=1&_v=a0&aip=true&_s=dt=This%20Picture%20Of%20A%20Dog%20Begging%20To%20Be%20Loved%20Helped%20Him%20Get%20Rescued&sr=375x667&_utmht=1454444552079&jid=&cid=GA1.2.74638031.1432311003&tid=UA-1740781-1&dl=http%3A%2F%2Fdev.buzzfeed.com%2Fbf2%2Famphtml%2Fmbvd%2Fpuppy-praying-to-be-adopted%3Fs%3Dmobile&dr=&t=pageview&_r=1&a=1818&z=0.8563434527052012&cd27=amp

rudygalfi commented 8 years ago

@ryanlombardo I believe you said this was working for you last week?

ryanlombardo commented 8 years ago

Yes, we tested it on Friday and I'm fairly certain that it was working.

Ryan Lombardo | BuzzFeed | Lead Software Engineer | @rlombardo

200 Fifth Ave, 8th Fl, New York, NY 10010

On Tue, Feb 2, 2016 at 3:39 PM, Rudy Galfi notifications@github.com wrote: @ryanlombardo [https://github.com/ryanlombardo] I believe you said this was working for you last week?

— Reply to this email directly or view it on GitHub [https://github.com/ampproject/amphtml/issues/1742#issuecomment-178809068] .[https://github.com/notifications/beacon/AAFCSdGauc8qkmZukYkFistmCzA7L3QKks5pgQt6gaJpZM4HR1qc.gif]

avimehta commented 8 years ago

Please override documentLocation variable and set it to CANONICAL_URL. We had to make the change because setting ampdocUrl to canonical Url did not make sense semantically.

rudygalfi commented 8 years ago

@ryanlombardo Hopefully @avimehta's suggestion helps resolve this. Please re-open if not.

ryanlombardo commented 8 years ago

It works! Thanks.

tzkmx commented 7 years ago

How to override documentLocation? I can't find anything like this on documentation or source code of the generated page.

avimehta commented 7 years ago

@tzkmx Does the following work?

<amp-analytics type="googleanalytics">
<script type="application/json">
{
  "vars": {
    "account": "UA-XXXXX-Y"
  },
  "triggers": {
    "trackPageviewWithDocumentLocation": {
      "on": "visible",
      "request": "pageview",
      "vars": {
        "documentLocation": "https://www.examplepetstore.com/pets.html"
      }
    }
  }
}
</script>
</amp-analytics>
tzkmx commented 7 years ago

Yeah, it does! Thanks a lot!