{"version":3,"file":"angulartics2-piwik.js","sources":["ng://angulartics2/piwik/piwik.ts","ng://angulartics2/piwik/angulartics2-piwik.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nimport { Angulartics2 } from 'angulartics2';\n\ndeclare var _paq: any;\n\n@Injectable({ providedIn: 'root' })\nexport class Angulartics2Piwik {\n\n constructor(private angulartics2: Angulartics2) {\n if (typeof (_paq) === 'undefined') {\n console.warn('Piwik not found');\n }\n this.angulartics2.setUsername\n .subscribe((x: string) => this.setUsername(x));\n this.angulartics2.setUserProperties\n .subscribe((x) => this.setUserProperties(x));\n }\n\n startTracking(): void {\n this.angulartics2.pageTrack\n .pipe(this.angulartics2.filterDeveloperMode())\n .subscribe((x) => this.pageTrack(x.path));\n this.angulartics2.eventTrack\n .pipe(this.angulartics2.filterDeveloperMode())\n .subscribe((x) => this.eventTrack(x.action, x.properties));\n }\n\n pageTrack(path: string, location?: any) {\n try {\n _paq.push(['setDocumentTitle', window.document.title]);\n _paq.push(['setCustomUrl', path]);\n _paq.push(['trackPageView']);\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n\n /**\n * Track a basic event in Piwik, or send an ecommerce event.\n *\n * @param action A string corresponding to the type of event that needs to be tracked.\n * @param properties The properties that need to be logged with the event.\n */\n eventTrack(action: string, properties: any = {}) {\n let params = [];\n switch (action) {\n /**\n * @description Sets the current page view as a product or category page view. When you call\n * setEcommerceView it must be followed by a call to trackPageView to record the product or\n * category page view.\n *\n * @link https://piwik.org/docs/ecommerce-analytics/#tracking-product-page-views-category-page-views-optional\n * @link https://developer.piwik.org/api-reference/tracking-javascript#ecommerce\n *\n * @property productSKU (required) SKU: Product unique identifier\n * @property productName (optional) Product name\n * @property categoryName (optional) Product category, or array of up to 5 categories\n * @property price (optional) Product Price as displayed on the page\n */\n case 'setEcommerceView':\n params = ['setEcommerceView',\n properties.productSKU,\n properties.productName,\n properties.categoryName,\n properties.price,\n ];\n break;\n\n /**\n * @description Adds a product into the ecommerce order. Must be called for each product in\n * the order.\n *\n * @link https://piwik.org/docs/ecommerce-analytics/#tracking-ecommerce-orders-items-purchased-required\n * @link https://developer.piwik.org/api-reference/tracking-javascript#ecommerce\n *\n * @property productSKU (required) SKU: Product unique identifier\n * @property productName (optional) Product name\n * @property categoryName (optional) Product category, or array of up to 5 categories\n * @property price (recommended) Product price\n * @property quantity (optional, default to 1) Product quantity\n */\n case 'addEcommerceItem':\n params = [\n 'addEcommerceItem',\n properties.productSKU,\n properties.productName,\n properties.productCategory,\n properties.price,\n properties.quantity,\n ];\n break;\n\n /**\n * @description Tracks a shopping cart. Call this javascript function every time a user is\n * adding, updating or deleting a product from the cart.\n *\n * @link https://piwik.org/docs/ecommerce-analytics/#tracking-add-to-cart-items-added-to-the-cart-optional\n * @link https://developer.piwik.org/api-reference/tracking-javascript#ecommerce\n *\n * @property grandTotal (required) Cart amount\n */\n case 'trackEcommerceCartUpdate':\n params = ['trackEcommerceCartUpdate', properties.grandTotal];\n break;\n\n /**\n * @description Tracks an Ecommerce order, including any ecommerce item previously added to\n * the order. orderId and grandTotal (ie. revenue) are required parameters.\n *\n * @link https://piwik.org/docs/ecommerce-analytics/#tracking-ecommerce-orders-items-purchased-required\n * @link https://developer.piwik.org/api-reference/tracking-javascript#ecommerce\n *\n * @property orderId (required) Unique Order ID\n * @property grandTotal (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)\n * @property subTotal (optional) Order sub total (excludes shipping)\n * @property tax (optional) Tax amount\n * @property shipping (optional) Shipping amount\n * @property discount (optional) Discount offered (set to false for unspecified parameter)\n */\n case 'trackEcommerceOrder':\n params = [\n 'trackEcommerceOrder',\n properties.orderId,\n properties.grandTotal,\n properties.subTotal,\n properties.tax,\n properties.shipping,\n properties.discount,\n ];\n break;\n\n /**\n * @description Tracks an Ecommerce goal\n *\n * @link https://piwik.org/docs/tracking-goals-web-analytics/\n * @link https://developer.piwik.org/guides/tracking-javascript-guide#manually-trigger-goal-conversions\n *\n * @property goalId (required) Unique Goal ID\n * @property value (optional) passed to goal tracking\n */\n case 'trackGoal':\n params = [\n 'trackGoal',\n properties.goalId,\n properties.value,\n ];\n break;\n\n /**\n * @description Tracks a site search\n *\n * @link https://piwik.org/docs/site-search/\n * @link https://developer.piwik.org/guides/tracking-javascript-guide#internal-search-tracking\n *\n * @property keyword (required) Keyword searched for\n * @property category (optional) Search category\n * @property searchCount (optional) Number of results\n */\n case 'trackSiteSearch':\n params = [\n 'trackSiteSearch',\n properties.keyword,\n properties.category,\n properties.searchCount,\n ];\n break;\n\n /**\n * @description Logs an event with an event category (Videos, Music, Games...), an event\n * action (Play, Pause, Duration, Add Playlist, Downloaded, Clicked...), and an optional\n * event name and optional numeric value.\n *\n * @link https://piwik.org/docs/event-tracking/\n * @link https://developer.piwik.org/api-reference/tracking-javascript#using-the-tracker-object\n *\n * @property category\n * @property action\n * @property name (optional, recommended)\n * @property value (optional)\n */\n default:\n // PAQ requires that eventValue be an integer, see: http://piwik.org/docs/event-tracking\n if (properties.value) {\n const parsed = parseInt(properties.value, 10);\n properties.value = isNaN(parsed) ? 0 : parsed;\n }\n\n params = [\n 'trackEvent',\n properties.category,\n action,\n properties.name || properties.label, // Changed in favour of Piwik documentation. Added fallback so it's backwards compatible.\n properties.value,\n ];\n }\n try {\n _paq.push(params);\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n\n setUsername(userId: string | boolean) {\n try {\n _paq.push(['setUserId', userId]);\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n\n /**\n * Sets custom dimensions if at least one property has the key \"dimension\",\n * e.g. dimension10. If there are custom dimensions, any other property is ignored.\n *\n * If there are no custom dimensions in the given properties object, the properties\n * object is saved as a custom variable.\n *\n * If in doubt, prefer custom dimensions.\n * @link https://piwik.org/docs/custom-variables/\n */\n setUserProperties(properties: any) {\n const dimensions = this.setCustomDimensions(properties);\n try {\n if (dimensions.length === 0) {\n _paq.push(['setCustomVariable', properties]);\n }\n } catch (e) {\n if (!(e instanceof ReferenceError)) {\n throw e;\n }\n }\n }\n\n private setCustomDimensions(properties: any): string[] {\n const dimensionRegex: RegExp = /dimension[1-9]\\d*/;\n const dimensions = Object.keys(properties)\n .filter(key => dimensionRegex.exec(key));\n dimensions.forEach(dimension => {\n const number = Number(dimension.substr(9));\n _paq.push(['setCustomDimension', number, properties[dimension]]);\n });\n return dimensions;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './piwik';\n"],"names":[],"mappings":";;;;IAOa,iBAAiB,GAA9B,MAAa,iBAAiB;IAE5B,YAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QAC5C,IAAI,QAAQ,IAAI,CAAC,KAAK,WAAW,EAAE;YACjC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;SACjC;QACD,IAAI,CAAC,YAAY,CAAC,WAAW;aAC1B,SAAS,CAAC,CAAC,CAAS,KAAK,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,YAAY,CAAC,iBAAiB;aAChC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD;IAED,aAAa;QACX,IAAI,CAAC,YAAY,CAAC,SAAS;aACxB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;aAC7C,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,CAAC,UAAU;aACzB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;aAC7C,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;KAC9D;IAED,SAAS,C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