Automattic / Automattic/jetpack
Jetpack Stats does not track outbound link clicks on AMP pages
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
As reported in an AMP plugin [support forum topic](https://wordpress.org/support/topic/pages-lose-validity-for-no-reason/):
> Jetpack stopped counting Users’ clicks on outbound links when I set up AMP. […] when I click on “Site Stats” for a single day, the right column is “Top Posts & Pages”, and under that report of pages is another report called “Clicks”. It says: “your visitors clicked these links on your site”. It should then list all the links clicked, which on my site are links to individual books and magazines that users opened.
>
> Since I installed AMP, it has said “No clicks recorded. (Clicks are viewers clicking outbound links on your site.)” I have no idea how Jetpack actually records the clicks.
The user is in the AMP plugin's Standard mode, so no non-AMP pages are being served. If not in Standard mode, there would be outbound clicks registered for non-AMP pages.
It appears that AMP-compat for the Stats module is currently limited to pixel tracking:
https://github.com/Automattic/jetpack/blob/ec48e84b8d68162e0bb7d70cc4cf28c2a63c94ab/modules/stats.php#L269-L279
So the AMP version only implements `view` but not `clickTrackerInit` as in the non-AMP version:
https://github.com/Automattic/jetpack/blob/ec48e84b8d68162e0bb7d70cc4cf28c2a63c94ab/modules/stats.php#L258-L263
It appears that using `amp-pixel` is too rudimentary for the needs of the Stats module, and that `amp-analytics` with an [in-house configuration](https://amp.dev/documentation/components/amp-analytics/#send-data-in-house) should be used instead.
See AMP documentation on [tracking page clicks](https://amp.dev/documentation/guides-and-tutorials/optimize-and-measure/configure-analytics/use_cases/?format=websites#tracking-page-clicks).
#### Steps to reproduce the issue
1. Enable Standard mode or Transitional mode
2. Go to an AMP page
3. Click an outbound link
4. No HTTP `c.gif` request is spawned upon clicking the link, e.g. `https://pixel.wp.com/c.gif?s=2&u={urlL}&r=&b=123456789&p=1235&rand=0.6138363861055471`
#### What I expected
Outbound link clicks should be tracked.
#### What happened instead
Only page views are tracked.
Contributor guide
Research direction
Start in modules/stats.php at the AMP compatibility code around lines 269-279, then compare it with the non-AMP clickTrackerInit code around lines 258-263 and the linked AMP click-tracking documentation. Done means an outbound link click on an AMP page produces the expected HTTP c.gif request and appears in Jetpack Stats, while page-view tracking continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- analytics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100