DavidWells / DavidWells/analytics

Plugin methods API issues

Open
#325 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.7k
Forks
267
PR merge metrics
No merged PRs in 30d

Description

Obsevations:

  1. The analytics instance is provided as a field instance on this when calling a method - this is shown in examples but not documented
  2. The analytics instance is provided as an additional parameter beyond the supplied ones when calling a method - this is not documented anywhere from what I can tell, and it could cause some bugs. For example I was making a method called gtag to push arguments into the Google Tag Manager but it has to just generically push all its arguments - the extra argument could have caused some confusion here.
  3. Plugin config is typically passed to all the event handlers on a plugin, but isn't passed into the method implementations, so I can take advantage of those options in the method. For example, if I wanted to use the dataLayerName option in a method, I can't do that.

Potential improvements:

  1. Update the docs to clarify what is passed into these things
  2. Make the config available somehow as well (maybe also on this although this-based APIs are kind of weird IMO)
  3. Maybe the methods could be a function that takes an object with instance, and config, and returns the method implementation functions bound to that config and instance from scope? That could help get around the issue with passing in config and avoid using this to supply arguments

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the plugin methods API and the examples referenced in the issue, then trace how instance, supplied arguments, and plugin config reach event handlers and method implementations. Before coding, clarify whether the goal is documentation only or an API redesign; done should include an agreed behavior for config access and documented argument handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.