Skip to content

Commit

Permalink
Send identification event to DOM + track for carpeso (#33)
Browse files Browse the repository at this point in the history
* send identification event to DOM + track for carpeso

* Fix lint
  • Loading branch information
HugoGresse authored Jul 6, 2022
1 parent 65077b0 commit f7b6482
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
// eslint-disable-next-line no-alert
alert(`Attachments clicked: ${e.detail.taxonName}`)
})
document.addEventListener('aiTaxonomistNewIdentification', () => {
// eslint-disable-next-line no-console
console.log("New identification")
})

const apiUrl = 'http://localhost:3000/v2/identify/all'
render(
Expand Down
12 changes: 12 additions & 0 deletions indexCarperso.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-JYSRPJM4V3"></script>
<script>
/* eslint-disable */
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-JYSRPJM4V3');
/* eslint-enable */
</script>
</head>
<body>
Expand All @@ -81,6 +83,16 @@
<a href="https://github.com/plantnet/ai-taxonomist-webcomponent" title="WebComponent GitHub" target="_blank">WebComponent repository</a>
</div>

<script>
document.addEventListener('aiTaxonomistNewIdentification', () => {
/* eslint-disable */
gtag("event", "identify", {
event_category: "identification",
event_label: "identification"
});
/* eslint-enable */
})
</script>
<script src="https://unpkg.com/ai-taxonomist/dist/src/index.js?module" type="module"></script>
<ai-taxonomist apiUrl="https://c4c.inria.fr/carpeso/api/classify" backendFormat="carp" > <center>Chargement...</center></ai-taxonomist>
</body>
Expand Down
8 changes: 8 additions & 0 deletions src/AiTaxonomist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ export class AiTaxonomist extends LitElement {
this.identify.error = null
this.identify.state = IdentifyState.Loading

this.dispatchEvent(
new CustomEvent('aiTaxonomistNewIdentification', {
bubbles: true,
composed: true,
cancelable: true,
})
)

const response = await identifyRequest(this.imageFiles, this.apiUrl, this.apiKey, this.backendFormat)

if (typeof response === 'string') {
Expand Down

0 comments on commit f7b6482

Please sign in to comment.