Piano Insight and Accelerated Mobile Pages (AMP) Implementation
The Accelerated Mobile Pages (AMP) Project is an open source initiative to build web pages for static content that render fast, with a focus on mobile devices.
Because AMP is based on "AMP HTML" and "AMP JS", Piano has implemented an AMP compatible tracking solution.
The implementation
Piano Insight integration into AMP pages is done by adding our amp-analytics tag at the start of the <body> section (see below for a full-page example)
|
|
NB! Remember to replace the siteId with your site ID! |
|
The tag above requires the 'amp-analytics' extension JavaScript included in the <head> section:
|
Inside the Piano Insight Dashboard
Within the Piano Insight dashboard, you can now analyze the traffic and user engagement of your AMP-specific content simply by doing a filter for the Custom Parameter 'cx_channel'. This Custom Parameter will be available once the above code implementation is carried out. By selecting this cx_channel => 'amp' custom parameter filter, you'll be filtering the various Dashboards to only show you the stats/information of who are engaging with your AMP content.
Custom Parameters
Custom Parameters can be passed by updating the above basic script like below;
|
Each Custom Parameter must be prefixed with cp_ and then, replace <CUSTOM_PARA_NAME> and <CUSTOM_PARA_VALUE> according to the Custom parameter Syntactical restrictions
ID Syncing
Traditional ID Syncing done via addExternalId can be done by modifying the basic script like below;
|
Replace <PREFIX> with the Site Group Prefix and <NAME_OF_COOKIE> with the Name of a Cookie that is saved on the Website that will hold the value of the External ID.
Segment Members
Segment Memberships can be retrieved for use in the following manner. This will be a separate Tag to the one described above.
|
Replace <PERSISTED_QUERY_ID> with the one that you are currently using to retrieve Segment Memberships. With the above code, the Segment Memberships will be placed in the segments variable which can be passed into an Ad request.
|
For the above to work you need to add two more additional JS libraries to the HTML
|
Segment Members for Ad Targeting
Segment Memberships for Ad Targeting can be retrieved in the Real Time Config (RTC) format. First, you will need to create a new Persisted Request similar to the one used by getUserSegmentIds()
|
Replace <LIST_OF_SITE_GROUP_IDS> appropriately as per instructions in /profile/user/segment. This will return a new ID to be used on the AMP Ad Tag.
A sample Ad Tag is as below. You will need to set the appropriate options in the Ad Tag based on your Ad Partner.
|
In the above sample, <NEW_PERSISTED_ID> is the ID returned by creating a new Persisted Request. As per this Pull Request to AMP, we are able to use the Visitors cX_P Cookie value.
|
AMP Ad requires the below JS libraries to the HTML
|
Reference documentation for the Piano Insight AMP Analytics implementation
-
https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/amp-analytics.md
-
https://github.com/ampproject/amphtml/blob/master/extensions/amp-analytics/analytics-vars.md
Examples
Live example
Full page example code
|
Advanced Configuration
A developer can build an advanced configuration using the example integration with parameters from this link:
https://www.ampproject.org/docs/reference/components/amp-analytics
GDPR and Consent
If you provide services to EU/EEA users, there might be a requirement to request for consent. AMP provides a consent collection solution:
https://www.ampproject.org/docs/reference/components/amp-consent
The recommendation is to add an attribute to <amp-analytics> if consent is required:
|