Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for data, plid, pvid request properties in Parse.ly analytics #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

joshuarrrr
Copy link

@joshuarrrr joshuarrrr commented Oct 14, 2019

Fixes https://github.com/Parsely/engineering/issues/912

Note that this adds the first default variable to the Parse.ly configuration, which makes the data match the generation logic of the standard tracker (it sends an empty {} by default). I also kept the order of properties as similar as possible to the standard tracker to aid in manual debugging.

The easiest way to use the new data property is to set it to a quote-escaped JSON string. For example:

<amp-analytics type="parsely">
<script type="application/json">
    {
        "vars": {
            "apikey": "example.com",
            "data": "{\"viewID\":\"${timestamp}-${pageViewId}\"}"
        }
    }
</script>
</amp-analytics>

There may be other better ways of passing arbitrary key/value pairs, or actually encoding the JSON strings, but this will likely work for now and was easy to implement.

@emmettbutler
Copy link

@joshuarrrr is your intent to have this reviewed by the Parsely team before pull requesting it against the mainline AMP codebase?

'requests': {
'host': 'https://srv.pixel.parsely.com',
'basePrefix':
'${host}/plogger/?' +
'rand=${timestamp}&' +
'plid=${pageViewId}&' +
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that by using the built-in ${pageViewId} variable substitution here, AMP pageviews will only send 4-digit plid values (such as 8726), as opposed to the 8-digit values sent by the Parse.ly tracker (such as 54412420). Other than the integer length, both systems use the same approach:

After a GitHub search across Parsely projects, I think this will be OK - we do need a value that can be cast to an int, due to our DPL schema: https://github.com/Parsely/parsely_raw_data/blob/303ae23349a888c1c821e4b9779eca245e42404b/parsely_raw_data/schema.py#L67

'title=${title}&' +
'date=${timestamp}&' +
'ampid=${clientId(_parsely_visitor)}',
'ampid=${clientId(_parsely_visitor)}&' +
'pvid=${pageViewId}',
Copy link
Author

@joshuarrrr joshuarrrr Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change explicitly assumes that all AMP pageloads can only send a single pageview. Furthermore, it means the plid and pvid for any AMP event will always be the same. While that's not how the normal Parse.ly tracker works, I don't think it should cause any problems. @rachelannelise does that approach seem OK to you?

While customers could add custom triggers to send multiple pageviews or bind to other events, I'd say that's a non-supported usage.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember how the plid and pvid work in the traditional tracker but because you're adding them to the template that's used for both the heartbeats and the pageview those, along with data, will be sent on pageviews and heartbeats. If that's not the desired behavior you can move any of them down into the pageview or heartbeat templates.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the intent here was to include those values on all events (both pageviews and heartbeats), as the values are used to group those events together in DPL queries: https://www.parse.ly/help/rawdata/schema#id-fields

@joshuarrrr
Copy link
Author

OK, this PR is ready for re-review, and I've tried to make explicit the assumptions that we're making with these changes in the code comments above.

Copy link

@cwisecarver cwisecarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC you'll need to update this file for the tests to pass.

'title=${title}&' +
'date=${timestamp}&' +
'ampid=${clientId(_parsely_visitor)}',
'ampid=${clientId(_parsely_visitor)}&' +
'pvid=${pageViewId}',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember how the plid and pvid work in the traditional tracker but because you're adding them to the template that's used for both the heartbeats and the pageview those, along with data, will be sent on pageviews and heartbeats. If that's not the desired behavior you can move any of them down into the pageview or heartbeat templates.

@@ -17,20 +17,26 @@
import {jsonLiteral} from '../../../../src/json';

const PARSELY_CONFIG = jsonLiteral({
'vars': {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need to add data here? This is just the generic template for parsely integration so it will be sent for every customer who doesn't have a custom implementation. Customers can choose to override these variables, requests, pageview, and heartbeat in their amp configuration in their implementation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's strictly necessary, but the intent here was to make the default AMP requests mimic the behavior of the standard tracker. With the standard Parse.ly tracker, the data property is always sent on all events, and it's default value is an empty object ({}) in cases where integrators don't pass any custom data. Without this variable definition, the AMP tracker equivalent would send an empty string instead. I figured consistency would make it easier to reason about in downstream systems, but if you think that adds too much overhead to the default template, we can remove.

@cwisecarver
Copy link

Here's what I did to get it working.

nvm install --lts # install node 12
git co master 
git remote add upstream [email protected]:ampproject/amphtml.git # set upstream to amphtml
git pull upstream master # pull from upstream into local master
git co - # checkout your branch again
git rebase master # rebase your changes onto master
yarn # install new node modules
gulp unit --local-changes # run the tests that would be impacted by local changes (except it actually seems to run everything)

FYI amp tests fail if you're behind a pi-hole

@joshuarrrr joshuarrrr force-pushed the enhancement/add-extra-data branch from e678c29 to 73ae5cf Compare October 23, 2019 20:25
@joshuarrrr joshuarrrr force-pushed the enhancement/add-extra-data branch from ffba8f0 to 7ea7b96 Compare October 23, 2019 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants