angulartics / angulartics-google-tag-manager

34 stars 35 forks source link

Prepend ng- to dataLayer event names to prevent collisions #4

Open DanWilkerson opened 8 years ago

DanWilkerson commented 8 years ago

Since other code may interoperate with the dataLayer, would anyone object to adding a prepended 'ng-' or 'nglytics-' to the values we're setting for the event property when we push it in? The logic here is pretty much the same as Angular prescribes in their docs for Directive naming - at some future point, Google or a 3rd party may introduce an event that would collide with a too-generic event name.

E.g.:

dataLayer.push({
  'event': 'interaction',
  ...
});

becomes

dataLayer.push({
  'event': 'nglytics-interaction',
  ...
});

One further step we could take would be to namespace all of our properties, too, like so:

dataLayer.push({
  'event': 'nglytics-interaction',
  'nglyticsVals': {
    'target': 'CATEGORY_NAME',
    'action': 'ACTION_NAME'
    ...
  }
});

Again, the idea being that someone else could set the 'label' property, which could be accidentally inherited by an event angulartics fires later on down the line, leading to some confusing and hard to debug issues.

Any objections? I can put together a PR with fixed docs etc.