electerious / ackee-tracker

Transfer data to Ackee.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automate `record` functionality (especially for SPAs)

trezy opened this issue · comments

commented

The idea here is to add opt-in functionality for automating the record functionality. My thought is that we could add a .watch() method that would...

  • Call the initial .record() function to initialise the record
  • Attach a listener to the window for popstate, calling .record() if the path has changed

The docs for this method would look something like this...


.watch(domainId, attributes, config)

Initialises a record and keeps it up-to-date when popstate events occur.

Examples:

instance.watch('https://ackee.example.com', {
	detailed: false,
	ignoreLocalhost: true,
}, {
	immediate: false,
})

Parameters:

  • domainId {String} Id of the domain.
  • attributes {?Object} Attributes that should be transferred to the server. Will be ackeeTracker.attributes() unless specified otherwise.
  • config {?Object} Configuration for the watcher.
    • config.immediate {?Boolean} Whether or not to call .record() immediately. If false, instance.record() must be called before instance.watch() to ensure the initial page is tracked. Defaults to true.
commented

FWIW, I'd be happy to make a PR if this is a feature the community would be interested in having.

This sounds like a nice idea that shouldn't be hard to implement. I'm however not sure if it's worth to build this directly into ackee-tracker. Most SPAs have a custom router logic that can take care of calling .record(). There's also use-ackee module for React to make that easier.

I'm closing this issue for now, but am willing to reopen it if there's more interest in such a feature.