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

feat: add auto-tracking plugin #570

Merged
merged 2 commits into from
Aug 31, 2023
Merged

feat: add auto-tracking plugin #570

merged 2 commits into from
Aug 31, 2023

Conversation

liuyang1520
Copy link
Contributor

@liuyang1520 liuyang1520 commented Aug 29, 2023

Summary

Extract the auto-tracking logic from #529 to a new package.

  • feat: add auto-tracking plugin

Instantiate the plugin

The plugin accepts 1 optional parameter, which is an Object to configure the allowed tracking options.

const plugin = autoTrackingPlugin({
  cssSelectorAllowlist: ['.amp-auto-tracking', '[amp-auto-tracking]'],
  tagAllowlist: ['button', 'a'],
});

Examples:

  • The above cssSelectorAllowlist will only allow tracking elements like:
    • <button amp-auto-tracking>Click</button>
    • <a class="amp-auto-tracking">Link</a>
  • The above tagAllowlist will only allow button and a tags to be tracked.

Note ingestionMetadata is for internal use only, you don't need to provide it.

Options

Name Type Default Description
cssSelectorAllowlist string[] undefined When provided, only allow elements matching any selector to be tracked.
tagAllowlist string[] ['a', 'button', 'input', 'select', 'textarea', 'label'] Only allow elements with tag in this list to be tracked.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

@liuyang1520 liuyang1520 force-pushed the add-auto-tracking-package branch from 32d0ef8 to 5987885 Compare August 29, 2023 23:51
@liuyang1520 liuyang1520 force-pushed the add-auto-tracking-package branch from 5987885 to d3cf27c Compare August 30, 2023 00:15
@liuyang1520 liuyang1520 requested review from a team August 30, 2023 00:19
@liuyang1520 liuyang1520 marked this pull request as ready for review August 30, 2023 00:19
@liuyang1520 liuyang1520 merged commit 757032f into v1.x Aug 31, 2023
@liuyang1520 liuyang1520 deleted the add-auto-tracking-package branch August 31, 2023 17:24
interface Options {
cssSelectorAllowlist?: string[];
tagAllowlist?: string[];
ingestionMetadata?: IngestionMetadata; // Should avoid overriding this if unplanned to do so, this is not available in the charts.
Copy link
Contributor

Choose a reason for hiding this comment

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

@liuyang1520 instead of including ingestionMetadata on the plugin Options, can it instead be retrieved in setup() via the client config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @justin-fiedler ! Good call, I can remove this override and use the existing client config one.

<br />
</p>

# @amplitude/plugin-auto-tracking-browser
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we get this name approved by growth and dx teams (or other stakeholders)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! This plugin is for internal use at present, will definitely need more discussion/approval about the naming and interface if we want to make it ready to public users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

are we publishing to npm? it'll still be public if so. and we can't rename packages in npm

Comment on lines +46 to +47
cssSelectorAllowlist: ['.amp-auto-tracking', '[amp-auto-tracking]'],
tagAllowlist: ['button', 'a'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

do these need to be separate or can we unify?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about this. The function is a little bit overlapping but not all are easy to configure. For tagAllowlist, if it is not provided, we have a list of default tags that we want to track, while cssSelectorAllowlist is for more advanced usage, if doesn't have a default list. If we just rely on cssSelectorAllowlist with a default list like ['button', 'a'], then problem is, when we want to add a allowed class, we have to do ['button.amp-auto-tracking', 'a.amp-auto-tracking'], need to explicitly copy all tags here (this is what I think not easy to configure). Let me know if you have any good thoughts on this, this interface is not ready to public users at the moment though.

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