Skip to content

Commit

Permalink
feat: Added conn.main_init event
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Dec 2, 2022
1 parent fe3d0b1 commit 1b1adf5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/conn/events/eventTypes.ts
Expand Up @@ -30,6 +30,17 @@ export interface ConnEventTypes {
*/
'conn.authenticated': undefined;
'conn.logout': undefined;
/**
* Triggered when the interface is booting
*
* @example
* ```javascript
* WPP.on('conn.main_init', () => {
* // Your code
* });
* ```
*/
'conn.main_init': undefined;
/**
* Triggered when the main interface is loaded, but is syncing
*
Expand Down
1 change: 1 addition & 0 deletions src/conn/events/index.ts
Expand Up @@ -17,6 +17,7 @@
import './registerAuthCodeChangeEvent';
import './registerAuthenticatedEvent';
import './registerLogoutEvent';
import './registerMainInit';
import './registerMainLoadedEvent';
import './registerMainReadyEvent';
import './registerNeedsUpdateEvent';
Expand Down
31 changes: 31 additions & 0 deletions src/conn/events/registerMainInit.ts
@@ -0,0 +1,31 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { internalEv } from '../../eventEmitter';
import * as webpack from '../../webpack';

webpack.onInjected(register);

function register() {
const check = setInterval(() => {
const version = (window as any).Debug?.VERSION;

if (version) {
clearInterval(check);
internalEv.emit('conn.main_init');
}
}, 100);
}
21 changes: 13 additions & 8 deletions src/gtag/index.ts
Expand Up @@ -41,21 +41,26 @@ internalEv.on('webpack.injected', () => {
mainTracker.setUserProperty('method', method);
mainTracker.setUserProperty('wa_js', waVersion);
mainTracker.setUserProperty('powered_by', config.poweredBy || '-');
mainTracker.setUserProperty(
'whatsapp',
(window as any).Debug?.VERSION || '-'
);

internalEv.on('conn.main_init', () => {
mainTracker.setUserProperty(
'whatsapp',
(window as any).Debug?.VERSION || '-'
);
});

mainTracker.trackEvent('page_view', { authenticated, method });

if (otherTracker) {
otherTracker.setUserProperty('method', method);
otherTracker.setUserProperty('wa_js', waVersion);
otherTracker.setUserProperty('powered_by', config.poweredBy || '-');
otherTracker.setUserProperty(
'whatsapp',
(window as any).Debug?.VERSION || '-'
);
internalEv.on('conn.main_init', () => {
otherTracker.setUserProperty(
'whatsapp',
(window as any).Debug?.VERSION || '-'
);
});

if (typeof config.googleAnalyticsUserProperty === 'object') {
for (const key in config.googleAnalyticsUserProperty) {
Expand Down

0 comments on commit 1b1adf5

Please sign in to comment.