File size: 7,197 Bytes
78185c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!--
  Matomo - free/libre analytics platform

  @link    https://matomo.org
  @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
-->

<template>
  <div>
    <a v-if="showMethodDetails"
       class="tracking-method-back"
       @click.prevent="showOverview();"
    >
      <span class="icon-chevron-left"></span>
      {{ translate('Mobile_NavigationBack') }}
    </a>

    <h1>{{ headline }}</h1>
    <p v-if="!loading && !showMethodDetails">
      {{ translate('BotTracking_SiteWithoutDataChooseTrackingMethodPreamble1') }}
      <br>
      {{ translate('BotTracking_SiteWithoutDataChooseTrackingMethodPreamble2') }}
    </p>

    <ActivityIndicator
      :loading-message="translate('BotTracking_DetectingYourSite')"
      :loading="loading"
    />

    <template v-if="!loading && !showMethodDetails">
      <div class="row" v-if="errorMessage">
        <span class="icon-warning"></span>
        <h2>{{ errorMessage }}</h2>
        <a class="btn" href="#" @click.prevent="fetchTrackingMethods()">
          {{ translate('General_Refresh') }}
        </a>
      </div>

      <div class="row tracking-method-detection" v-if="recommendedMethod">
        <img :src="recommendedMethod.icon" :alt="`${recommendedMethod.name} logo`" />
        <h2>
          {{ translate(
            'BotTracking_SiteWithoutDataInstallWithXRecommendation',
            recommendedMethod.name,
          ) }}
        </h2>
        <p>
          {{ translate(
            'BotTracking_SiteWithoutDataRecommendationText',
            recommendedMethod.name,
          ) }}
        </p>
        <a :href="`#${recommendedMethod.id.toLowerCase()}`"
           class="btn"
           @click.prevent="showMethod(recommendedMethod.id)">
          {{ translate(
            'BotTracking_SiteWithoutDataInstallWithX',
            recommendedMethod.name,
          ) }}
        </a>
      </div>

      <div class="row tracking-method-list">
        <span class="icon-search"></span>
        <h2>{{ translate('BotTracking_SiteWithoutDataOtherInstallMethods') }}</h2>
        <p>{{ translate('BotTracking_SiteWithoutDataOtherInstallMethodsIntro') }}</p>
        <ul>
          <li class="list-entry" v-for="method in trackingMethods" :key="method.id">
            <a
              v-if="method.content"
              :href="`#${method.id.toLowerCase()}`"
              @click.prevent="showMethod(method.id)"
            >
              <img :src="method.icon" class="list-entry-icon" v-if="method.icon" />
              <span v-else class="list-entry-icon" aria-hidden="true"></span>
              <span class="list-entry-text">{{ method.name }}</span>
            </a>
            <a
              v-else-if="method.link"
              :href="method.link"
              target="_blank"
              rel="noreferrer noopener"
            >
              <img :src="method.icon" class="list-entry-icon" v-if="method.icon" />
              <span v-else class="list-entry-icon" aria-hidden="true"></span>
              <span class="list-entry-text">{{ method.name }}</span>
            </a>
          </li>
        </ul>
      </div>

      <div class="tracking-method-skip">
        <h2>{{ translate('BotTracking_SiteWithoutDataNotYetReady') }}</h2>
        <a :href="backToMatomoLink">
          {{ translate('BotTracking_SiteWithoutDataBackToMatomo') }}
        </a>
      </div>
    </template>

    <div v-if="showMethodDetails"
         class="tracking-method-details"
         :data-method="showMethodDetails.id">
      <img :src="showMethodDetails.icon" :alt="`${showMethodDetails.name} logo`" />
      <VueEntryContainer :html="showMethodDetails.content" />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, watch } from 'vue';
import {
  translate,
  ActivityIndicator,
  AjaxHelper,
  Matomo,
  MatomoUrl,
  VueEntryContainer,
} from 'CoreHome';

interface TrackingMethod {
  id: string,
  name: string,
  content: string,
  link?: string,
  icon: string,
  priority: number,
  isOthers: boolean,
  wasDetected: boolean
}
interface SiteWithoutDataState {
  loading: boolean,
  errorMessage: string|null,
  showMethodDetails: TrackingMethod|null;
  recommendedMethod: TrackingMethod|null,
  trackingMethods: Array<TrackingMethod>,
}

export default defineComponent({
  components: {
    ActivityIndicator,
    VueEntryContainer,
  },
  props: {
    backToMatomoLink: String,
  },
  data(): SiteWithoutDataState {
    return {
      loading: true,
      errorMessage: null,
      showMethodDetails: null,
      recommendedMethod: null,
      trackingMethods: [],
    };
  },
  created() {
    watch(() => MatomoUrl.hashParsed.value.activeTab as string, (activeTab) => {
      this.showMethodDetails = this.findTrackingMethod(activeTab);
    });

    this.fetchTrackingMethods();
  },
  methods: {
    fetchTrackingMethods() {
      const params: QueryParameters = {
        module: 'BotTracking',
        action: 'getTrackingMethodsForSite',
        idSite: Matomo.idSite,
      };

      this.loading = true;
      this.errorMessage = null;

      AjaxHelper.fetch(params).then((response) => {
        const trackingMethods = Array.isArray(response?.trackingMethods)
          ? [...response.trackingMethods]
          : [];
        const recommendedIndex = trackingMethods.findIndex((method) => method.wasDetected);

        if (recommendedIndex !== -1) {
          this.recommendedMethod = trackingMethods[recommendedIndex];
          trackingMethods.splice(recommendedIndex, 1);
        } else {
          this.recommendedMethod = null;
        }

        this.trackingMethods = trackingMethods;
      }).catch(() => {
        this.errorMessage = translate('General_ErrorRequest', '', '');
        this.recommendedMethod = null;
        this.trackingMethods = [];
      }).finally(() => {
        this.loading = false;
        this.showMethodDetails = this.findTrackingMethod(
          MatomoUrl.hashParsed.value.activeTab as string,
        );
      });
    },
    findTrackingMethod(methodId: string|null) {
      if (
        this.recommendedMethod
        && methodId
        && this.recommendedMethod.id.toLowerCase() === methodId.toLowerCase()
      ) {
        return this.recommendedMethod;
      }

      let trackingMethod = null;

      Object.entries(this.trackingMethods).forEach(([, method]) => {
        if (methodId && method.id.toLowerCase() === methodId.toLowerCase() && method.content) {
          trackingMethod = method;
        }
      });

      return trackingMethod;
    },
    showMethod(methodId: string) {
      MatomoUrl.updateHash({ ...MatomoUrl.hashParsed.value, activeTab: methodId.toLowerCase() });
    },
    showOverview() {
      MatomoUrl.updateHash({ ...MatomoUrl.hashParsed.value, activeTab: null });
    },
  },
  computed: {
    headline(): string {
      if (this.showMethodDetails && this.showMethodDetails.name) {
        if (this.showMethodDetails.isOthers) {
          return this.showMethodDetails.name;
        }

        return translate('BotTracking_SiteWithoutDataInstallWithX', this.showMethodDetails.name);
      }
      return translate('BotTracking_SiteWithoutDataChooseTrackingMethod');
    },
  },
});
</script>