@@ -97,9 +97,9 @@ export default class DuckAiListener extends ContentFeature {
9797
9898 async setup ( ) {
9999 this . createButtonUI ( ) ;
100+ this . setupTelemetry ( ) ;
100101 await this . setupMessageBridge ( ) ;
101102 this . setupTextBoxDetection ( ) ;
102- this . setupTelemetry ( ) ;
103103 this . cleanupExistingPrompts ( ) ;
104104 this . setupPromptCleanupObserver ( ) ;
105105 }
@@ -834,7 +834,8 @@ export default class DuckAiListener extends ContentFeature {
834834 this . triggerInputEvents ( ) ;
835835
836836 // Capture prompt text for telemetry before any modifications
837- if ( this . textBox && this . promptTelemetry ) {
837+ // Only send telemetry if context hasn't been used yet (first prompt)
838+ if ( this . textBox && this . promptTelemetry && ! this . hasContextBeenUsed ) {
838839 const rawPromptText = this . getRawPromptText ( ) ;
839840 const totalPromptText = this . textBox . value ; // This includes context if enabled
840841 const contextSize = this . pageData ?. content ?. length || 0 ;
@@ -1354,10 +1355,13 @@ class DuckAiPromptTelemetry {
13541355 * @param {Object } params - Parameters to send with pixel
13551356 */
13561357 sendPixel ( pixelName , params ) {
1357- if ( ! globalThis ?. DDG ?. pixel ) {
1358+ if ( ! globalThis ?. DDG ?. pixel ?. fire ) {
1359+ this . log . warn ( 'sendPixel: No pixel object found' ) ;
13581360 return ;
13591361 }
13601362 globalThis . DDG . pixel . fire ( pixelName , params ) ;
1363+
1364+ this . log . info ( 'Pixel sent' , { pixelName, params } ) ;
13611365 }
13621366
13631367 /**
@@ -1376,6 +1380,7 @@ class DuckAiPromptTelemetry {
13761380 /**
13771381 * Send context pixel info when context is used
13781382 * @param {Object } contextData - Context data object
1383+ * @param {string } pixelName - Name of pixel to fire
13791384 */
13801385 sendContextPixelInfo ( contextData , pixelName ) {
13811386 if ( ! contextData ?. content || contextData . content . length === 0 ) {
@@ -1384,7 +1389,7 @@ class DuckAiPromptTelemetry {
13841389 }
13851390
13861391 this . sendPixel ( pixelName , {
1387- contextLength : contextData . content . length ,
1392+ contextLength : contextData . fullContentLength ,
13881393 } ) ;
13891394 }
13901395
0 commit comments