1.8.0 • Published 2 years ago

@s-ui/html-tagger v1.8.0

Weekly downloads
57
License
-
Repository
-
Last release
2 years ago

@s-ui/html-tagger

Tool to tag the HTML of your webpage from a service.

It provides:

  • A way to tag HTML elements, perfect for add tracking on SPAs.
  • Performance focused in order to avoid jank and heavy script load.

Use:

import { tagHTML } from '@s-ui/html-tagger'
// create an object like this
const tags = {
  'CSS_SELECTOR_OF_THE_ELEMENT_TO_TAG': {
    'DATA_TAG_NAME_TO_ADD': 'DATA_TAG_VALUE_TO_ADD'
  },
  '.simple-div': {
    'tracking-tag': 'c_tracking_tag'
  },
  '.button': {
    'tracking-tag': 'c_tracking_button'
  },
  '.added-later': {
    'tracking-tag': 'c_tracking_dynamic'
  }
}

// execute the method and use the created tags
tagHTML({ tags })

Performance:

  • It uses requestIdleCallback if supported, in order to only tag when the browser is idle. If not available, it tries to use requestAnimationFrame in order to tag elements smoothly.
  • It uses MutationObserver if supported in order to only tag elements when these are added.

Debugger:

You can use this command in the console to check if the tagging has worked correctly.

console.table(
  Array.from(document.querySelectorAll('[data-tracking-tag]'))
)
1.8.0

2 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

6 years ago