Skip to content

Commit f543326

Browse files
committed
use single quotes
1 parent 97d82f1 commit f543326

File tree

3 files changed

+54
-53
lines changed

3 files changed

+54
-53
lines changed

src/analytics.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
/* */
12
// Utils.
2-
import "./utils/polyfills";
3-
import { uuid, getLanguage } from "./utils";
4-
import UAParser from "ua-parser-js";
3+
import './utils/polyfills';
4+
import { uuid, getLanguage } from './utils';
5+
import UAParser from 'ua-parser-js';
56
import merge from 'deepmerge';
67

78
// AWS SDK.
8-
import { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity-browser/CognitoIdentityClient";
9-
import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity-browser/commands/GetCredentialsForIdentityCommand";
10-
import { GetIdCommand } from "@aws-sdk/client-cognito-identity-browser/commands/GetIdCommand";
11-
import { PinpointClient } from "@aws-sdk/client-pinpoint-browser/PinpointClient";
12-
import { PutEventsCommand } from "@aws-sdk/client-pinpoint-browser/commands/PutEventsCommand";
9+
import { CognitoIdentityClient } from '@aws-sdk/client-cognito-identity-browser/CognitoIdentityClient';
10+
import { GetCredentialsForIdentityCommand } from '@aws-sdk/client-cognito-identity-browser/commands/GetCredentialsForIdentityCommand';
11+
import { GetIdCommand } from '@aws-sdk/client-cognito-identity-browser/commands/GetIdCommand';
12+
import { PinpointClient } from '@aws-sdk/client-pinpoint-browser/PinpointClient';
13+
import { PutEventsCommand } from '@aws-sdk/client-pinpoint-browser/commands/PutEventsCommand';
1314

1415
const {
1516
_attributes,
@@ -52,7 +53,7 @@ let elapsed = 0;
5253
*/
5354
let scrollDepthMax = 0;
5455
let scrollDepthNow = 0;
55-
window.addEventListener( "scroll", () => {
56+
window.addEventListener( 'scroll', () => {
5657
const percent = ( window.scrollY / document.body.clientHeight ) * 100;
5758
scrollDepthMax = percent > scrollDepthMax ? percent : scrollDepthMax;
5859
scrollDepthNow = percent;
@@ -63,29 +64,29 @@ window.addEventListener( "scroll", () => {
6364
*/
6465
const params = new URLSearchParams( window.location.search );
6566
const utm = {
66-
utm_source: params.get( "utm_source" ) || "",
67-
utm_medium: params.get( "utm_medium" ) || "",
68-
utm_campaign: params.get( "utm_campaign" ) || ""
67+
utm_source: params.get( 'utm_source' ) || '',
68+
utm_medium: params.get( 'utm_medium' ) || '',
69+
utm_campaign: params.get( 'utm_campaign' ) || ''
6970
};
7071

7172
/**
7273
* Attributes helper.
7374
*/
7475
const getSessionID = () => {
75-
if ( typeof window.sessionStorage === "undefined" ) {
76+
if ( typeof window.sessionStorage === 'undefined' ) {
7677
return null;
7778
}
7879

7980
// Get stored session.
80-
const sessionID = window.sessionStorage.getItem( "_hm_uuid" );
81+
const sessionID = window.sessionStorage.getItem( '_hm_uuid' );
8182

8283
if ( sessionID ) {
8384
return sessionID;
8485
}
8586

8687
// Create and set a UUID.
8788
const newSessionID = uuid();
88-
window.sessionStorage.setItem( "_hm_uuid", newSessionID );
89+
window.sessionStorage.setItem( '_hm_uuid', newSessionID );
8990
return newSessionID;
9091
};
9192
const getSearchParams = () =>
@@ -196,7 +197,7 @@ const Analytics = {
196197
// Get user credentials for pinpoint client.
197198
const Credentials = await Analytics.authenticate();
198199
if ( !Credentials ) {
199-
console.error( "Credentials not found.", error );
200+
console.error( 'Credentials not found.', error );
200201
return;
201202
}
202203

@@ -238,7 +239,7 @@ const Analytics = {
238239
const EndpointData = {
239240
Attributes: {},
240241
Demographic: {
241-
AppVersion: Data.AppVersion || "",
242+
AppVersion: Data.AppVersion || '',
242243
Locale: getLanguage(),
243244
},
244245
Location: {},
@@ -301,9 +302,9 @@ const Analytics = {
301302
[ EventId ]: {
302303
EventType: type /* required */,
303304
Timestamp: new Date().toISOString(),
304-
AppPackageName: Data.AppPackageName || "",
305-
AppTitle: Data.SiteName || "",
306-
AppVersionCode: Data.AppVersion || "",
305+
AppPackageName: Data.AppPackageName || '',
306+
AppTitle: Data.SiteName || '',
307+
AppVersionCode: Data.AppVersion || '',
307308
Attributes: Object.assign( {}, data.attributes || {} ),
308309
Metrics: Object.assign( {}, data.metrics || {} ),
309310
Session: {
@@ -314,7 +315,7 @@ const Analytics = {
314315
};
315316

316317
// Add session stop parameters.
317-
if ( type === "_session.stop" ) {
318+
if ( type === '_session.stop' ) {
318319
Event[ EventId ].Session.Duration = Date.now() - subSessionStart;
319320
Event[ EventId ].Session.StopTimestamp = new Date().toISOString();
320321
}
@@ -342,7 +343,7 @@ const Analytics = {
342343
// Events are associated with an endpoint.
343344
const UserId = Analytics.getUserId();
344345
if ( !UserId ) {
345-
console.error( "No User ID found. Make sure to call Analytics.authenticate() first." );
346+
console.error( 'No User ID found. Make sure to call Analytics.authenticate() first.' );
346347
return;
347348
}
348349

@@ -359,7 +360,7 @@ const Analytics = {
359360
const Events = Analytics.events.reduce( ( carry, event ) => ( { ...event, ...carry } ), {} );
360361

361362
// Build events request object.
362-
const BatchUserId = UserId.replace( `${ Config.CognitoRegion }:`, "" );
363+
const BatchUserId = UserId.replace( `${ Config.CognitoRegion }:`, '' );
363364
const EventsRequest = {
364365
BatchItem: {
365366
[ BatchUserId ]: {
@@ -390,12 +391,12 @@ const Analytics = {
390391
Analytics.mergeEndpointData( Data.Endpoint || {} );
391392

392393
// Track sessions.
393-
document.addEventListener( "visibilitychange", () => {
394+
document.addEventListener( 'visibilitychange', () => {
394395
if ( document.hidden ) {
395396
// On hide increment elapsed time.
396397
elapsed += Date.now() - start;
397398
// Fire session stop event.
398-
Analytics.record( "_session.stop", {
399+
Analytics.record( '_session.stop', {
399400
attributes: getAttributes( {} ),
400401
metrics: getMetrics( {} )
401402
} );
@@ -406,21 +407,21 @@ document.addEventListener( "visibilitychange", () => {
406407
subSessionId = uuid();
407408
subSessionStart = Date.now();
408409
// Fire session start event.
409-
Analytics.record( "_session.start", {
410+
Analytics.record( '_session.start', {
410411
attributes: getAttributes( {} )
411412
} );
412413
}
413414
} );
414415

415416
// Start recording after document loaded and tests applied.
416-
window.addEventListener( "DOMContentLoaded", () => {
417+
window.addEventListener( 'DOMContentLoaded', () => {
417418
// Session start.
418-
Analytics.record( "_session.start", {
419+
Analytics.record( '_session.start', {
419420
attributes: getAttributes()
420421
} );
421422
// Record page view event & create/update endpoint immediately.
422423
Analytics.record(
423-
"pageView",
424+
'pageView',
424425
{
425426
attributes: getAttributes()
426427
},
@@ -430,8 +431,8 @@ window.addEventListener( "DOMContentLoaded", () => {
430431
} );
431432

432433
// Flush remaining events.
433-
window.addEventListener( "beforeunload", async () => {
434-
Analytics.record( "_session.stop", {
434+
window.addEventListener( 'beforeunload', async () => {
435+
Analytics.record( '_session.stop', {
435436
attributes: getAttributes( {} ),
436437
metrics: getMetrics( {} )
437438
} );

src/utils/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* Generate a UUID v4 string.
77
*/
88
export const uuid = placeholder =>
9-
placeholder
10-
? ( placeholder ^ ( ( Math.random() * 16 ) >> ( placeholder / 4 ) ) ).toString( 16 )
11-
: ( [ 1e7 ] + -1e3 + -4e3 + -8e3 + -1e11 ).replace( /[018]/g, uuid );
9+
placeholder
10+
? ( placeholder ^ ( ( Math.random() * 16 ) >> ( placeholder / 4 ) ) ).toString( 16 )
11+
: ( [ 1e7 ] + -1e3 + -4e3 + -8e3 + -1e11 ).replace( /[018]/g, uuid );
1212

1313
/**
1414
* Get a throttled version of a function to reduce event trigger rates.
@@ -17,15 +17,15 @@ export const uuid = placeholder =>
1717
* @param {callable} fn Callback.
1818
*/
1919
export const throttle = ( delay, fn ) => {
20-
let lastCall = 0;
21-
return function ( ...args ) {
22-
const now = ( new Date ).getTime();
23-
if ( now - lastCall < delay ) {
24-
return;
25-
}
26-
lastCall = now;
27-
return fn( ...args );
28-
}
20+
let lastCall = 0;
21+
return function ( ...args ) {
22+
const now = ( new Date ).getTime();
23+
if ( now - lastCall < delay ) {
24+
return;
25+
}
26+
lastCall = now;
27+
return fn( ...args );
28+
}
2929
}
3030

3131
/**

src/utils/polyfills.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
* Polyfills CustomEvent.
33
*/
44
( function () {
5-
if ( typeof window.CustomEvent === "function" ) {
6-
return false;
7-
}
5+
if ( typeof window.CustomEvent === 'function' ) {
6+
return false;
7+
}
88

9-
function CustomEvent( event, params ) {
10-
params = params || { bubbles: false, cancelable: false, detail: null };
11-
var evt = document.createEvent( 'CustomEvent' );
12-
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
13-
return evt;
14-
}
9+
function CustomEvent( event, params ) {
10+
params = params || { bubbles: false, cancelable: false, detail: null };
11+
var evt = document.createEvent( 'CustomEvent' );
12+
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
13+
return evt;
14+
}
1515

16-
window.CustomEvent = CustomEvent;
16+
window.CustomEvent = CustomEvent;
1717
} )();

0 commit comments

Comments
 (0)