const defaultState = {
  items: [],
}

const store = {
  state: JSON.parse(localStorage.getItem('userCollections')) || defaultState,

  getItems() {
    return this.state.items
  },

  addItem(itemId) {
    this.state.items.push({id: itemId})
    this._saveState()
  },

  removeItem(itemId) {
    this.state.items = this.state.items.filter(({id}) => id !== itemId)
    this._saveState()
  },

  hasItem(itemId) {
    return this.state.items.findIndex(({id}) => id === itemId) > -1
  },

  toggleItem(itemId) {
    this.hasItem(itemId) ? this.removeItem(itemId) : this.addItem(itemId)
  },

  clearAllItems() {
    this.state.items = []
    this._saveState()
  },

  _saveState() {
    localStorage.setItem('userCollections', JSON.stringify(this.state))
  },
}

module.exports = store

@@ -258,21 +258,56 @@
 State()%0A
+    this._track('addItem', itemId)%0A
   %7D,%0A
-
 %0A  remov
@@ -408,32 +408,70 @@
 is._saveState()%0A
+    this._track('removeItem', itemId)%0A
   %7D,%0A%0A  hasItem(
@@ -725,16 +725,55 @@
 State()%0A
+    this._track('clearAllItems', null)%0A
   %7D,%0A%0A  
@@ -859,20 +859,325 @@
 state))%0A
-
   %7D,
+%0A%0A  // GTM Tracking%0A  _track(actionName, itemId) %7B%0A    if (!window.dataLayer) return%0A%0A    window.dataLayer.push(%7B%0A      'event': 'UserCollectionEvent',%0A      'eventCategory': 'UserCollection',%0A      'eventAction': actionName,%0A      'eventLabel': itemId,%0A      'userCollection': this.state.items%0A    %7D)%0A  %7D
 %0A%7D%0A%0Amodu

Add basic GTM tracking for user collections