Google AMP instrumentation for Marfeel analytics tracking
Marfeel tracks AMP page views with the native amp-analytics element. This guide covers both standard and consent-aware implementations, so you can choose the right setup for your pages.
Add AMP Analytics
Section titled “Add AMP Analytics”If you are not already using amp-analytics in your pages, add the following script tag in the head of all your pages that Compass should track.
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>This script must be present only once in your AMP pages. If you already have it, do not add it again.
Two AMP implementations are available. Choose one based on your amp-consent setup and how you want to track your users.
Enable Compass in AMP pages without amp-consent
Section titled “Enable Compass in AMP pages without amp-consent”Use this code if you do not have an amp-consent element in your pages, or you want to manually use block-on-consent.
Initialize the amp-analytics in the <body> of your AMP pages, ensuring your unique account ID is correctly added before /* AccountId */:
<amp-analytics config="https://sdk.newsroom.bi/amp.v1.json" data-credentials="include"> <script type="application/json" > { "vars" : { "accountId": "/* AccountId */" } } </script></amp-analytics>AMP tracker with amp-consent
Section titled “AMP tracker with amp-consent”Using this implementation without AMP consent may cause duplicated users and pages.
This option adds full support to track CMP metrics and Private sessions on AMP, giving you complete visibility into your audience.
This code correctly tracks the Consent Choice in AMP with values Accepted, Rejected, No CMP, and No Choice.
Note the change on the config attribute from v1.json to v2.json:
<amp-analytics config="https://sdk.newsroom.bi/amp.v2.json" data-credentials="include"> <script type="application/json" > { "vars" : { "accountId": "/* AccountId */" } } </script></amp-analytics>Consent timeout behavior
Section titled “Consent timeout behavior”Marfeel monitors consent choices through a default 5-second timeout due to amp-analytics and amp-consent constraints:
- If the user accepts or rejects consent before this timeout, the user is classified:
- Accept:
User loyalty = newandconsent choice = Accepted - Reject:
User loyalty = privateandconsent choice = Rejected
- Accept:
- If the timeout triggers:
User loyalty = privateandconsent choice = No Choice
- If the user later accepts or rejects, both
User Loyaltyandconsent choiceupdate accordingly.
In the aggregated Explore reports, when a session is first tracked as private (due to no choice) and then as new (after being accepted), the user will be counted if they are grouped by “Visitor loyalty” in both the New and Private groups. They will only be counted once in the total count.
By default the timeout is set to 5s. It can be customized via a url queryparam
https://sdk.newsroom.bi/amp.v2.json?timeout=10
Timeout trade-offs
Section titled “Timeout trade-offs”Keep these trade-offs in mind when modifying the default timeout:
- If you increase the timeout, sessions that last less than the indicated timeout will not be tracked at all.
- If you decrease the timeout, sessions will double count as explained above in grouped Explore reports.
Ads in AMP
Section titled “Ads in AMP”To properly track ads, add the parameter data-vars-ad-slot to the amp-ad element with its slotname information. For more details on ads tracking setup, see the dedicated guide.
<amp-ad width="300" height="250" type="foo" data-vars-ad-slot="SLOTNAME"> <div placeholder>Loading ...</div></amp-ad>Custom page technology
Section titled “Custom page technology”On AMP you can override the default pageType by adding a var directly on the Marfeel snippet:
<amp-analytics config="https://sdk.newsroom.bi/amp.v1.json" data-credentials="include"> <script type="application/json" > { "vars" : { "accountId": "/* AccountId */" }, "extraUrlParams": { "pageType": 3 } } </script></amp-analytics>Infinite scroll using amp-next-page
Section titled “Infinite scroll using amp-next-page”Add the utm_pp parameter with the previous URL (encoded) along with utm_cpm_rs=amp-page-next. For example:
https://www.marfeel.com/destination-url.html?utm_cmp_rs=amp-next-page&utm_pp=https%3A%2F%2Fwww.marfeel.com%2Fprevious-url.htmlWhich AMP implementation should I use, v1 or v2?
Use v1 (amp.v1.json) if you do not have an amp-consent element or want to manually manage block-on-consent. Use v2 (amp.v2.json) if you have amp-consent and need full CMP metrics and Private session tracking. Never use v2 without amp-consent, as it may cause duplicated users and pages.
How does Marfeel handle consent timeouts on AMP pages?
Marfeel monitors consent choices through a default 5-second timeout. If the user accepts or rejects before the timeout, they are classified accordingly. If the timeout triggers without a response, the user is marked as private with No Choice. Accepting or rejecting later updates both User Loyalty and consent choice. The timeout is customizable via URL query parameter.
What happens if I change the default consent timeout?
Increasing the timeout means sessions shorter than that value will not be tracked at all. Decreasing the timeout causes sessions to double count in grouped Explore reports, because a user may first appear as private and then as new after consent is granted.