Skip to content

Commit dec7d12

Browse files
committed
♻️ refactor code
1 parent 5c68a85 commit dec7d12

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

sourcelink.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sourcelink.js.LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
*
33
* Copyright (c) 2025 Praba Ponnambalam
4-
* Version: 1.4.0
4+
* Version: 1.4.1
55
* Released under the MIT License.
66
*
77
*/

sourcelinkdev.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
4040
'twclid',
4141
];
4242

43-
// Get client ID from script tag
43+
// Get pixel ID from script tag
4444
const scriptTag = document.currentScript;
4545
const scriptUrl = scriptTag.src;
4646

4747
// Parse query string manually
48-
const getClientId = (url) => {
48+
const getPixelId = (url) => {
4949
const queryString = url.split('?')[1];
5050
if (!queryString) return null;
5151

5252
const params = new URLSearchParams(queryString);
53-
return params.get('clientId');
53+
return params.get('pixelId');
5454
};
5555

56-
const clientId = getClientId(scriptUrl);
56+
const pixelId = getPixelId(scriptUrl);
5757

58-
if (!clientId) {
58+
if (!pixelId) {
5959
console.error('Pixel ID is required');
6060
return;
6161
}
6262

63-
const CLIENT_ID = clientId.toUpperCase();
64-
const SESSION_KEY = `_source_link_${CLIENT_ID}`;
63+
const PIXEL_ID = pixelId.toUpperCase();
64+
const SESSION_KEY = `_source_link_${PIXEL_ID}`;
6565

6666
// Utility Functions
6767
const getCookie = (name) => {
@@ -104,7 +104,7 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
104104
if (!response.ok) {
105105
if (response.status === 403) {
106106
console.warn(
107-
`🚫 SourceLink disabled - Pixel ${CLIENT_ID} is inactive`,
107+
`🚫 SourceLink disabled - Pixel ${PIXEL_ID} is inactive`,
108108
);
109109
} else {
110110
console.warn(`⚠️ Source tracking error - Status: ${response.status}`);
@@ -141,15 +141,15 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
141141
};
142142

143143
// Core Functions
144-
const validateClient = async () => {
144+
const validatePixel = async () => {
145145
const cachedStatus = sessionStorage.getItem(SESSION_KEY);
146146
if (cachedStatus !== null) {
147147
return cachedStatus === 'true';
148148
}
149149

150150
const validationData = {
151151
action: ACTIONS.VALIDATE,
152-
clientId: CLIENT_ID,
152+
pixelId: PIXEL_ID,
153153
websiteId: PAGE_DOMAIN,
154154
visitorId: 'validation_check',
155155
};
@@ -170,7 +170,7 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
170170

171171
const firestoreData = {
172172
action: ACTIONS.CREATE_VISITOR,
173-
clientId: CLIENT_ID,
173+
pixelId: PIXEL_ID,
174174
websiteId: PAGE_DOMAIN,
175175
visitorId: visitorId,
176176
createdAt: Date.now(),
@@ -182,7 +182,7 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
182182

183183
if (response.success) {
184184
const cookieData = {
185-
clientId: CLIENT_ID,
185+
pixelId: PIXEL_ID,
186186
websiteId: PAGE_DOMAIN,
187187
visitorId: visitorId,
188188
referrer: data.sourceData[0].referrer,
@@ -203,7 +203,7 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
203203
const updateFirestoreWithNewSource = async (visitorId, newData) => {
204204
const updateData = {
205205
action: ACTIONS.UPDATE_SOURCE,
206-
clientId: CLIENT_ID,
206+
pixelId: PIXEL_ID,
207207
websiteId: PAGE_DOMAIN,
208208
visitorId: visitorId,
209209
sourceData: [newData],
@@ -239,7 +239,7 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
239239
if (visitorId) {
240240
const data = {
241241
action: ACTIONS.UPDATE_EMAIL,
242-
clientId: CLIENT_ID,
242+
pixelId: PIXEL_ID,
243243
websiteId: PAGE_DOMAIN,
244244
visitorId: visitorId,
245245
email: email,
@@ -327,9 +327,9 @@ const cloudFunctionUrl = "https://us-west1-ms-source-tracking-tool-dev.cloudfunc
327327

328328
// Initialize the app
329329
const init = async () => {
330-
const isActive = await validateClient();
330+
const isActive = await validatePixel();
331331
if (!isActive) {
332-
console.warn(`🚫 SourceLink disabled - Pixel ${CLIENT_ID} is inactive`);
332+
console.warn(`🚫 SourceLink disabled - Pixel ${PIXEL_ID} is inactive`);
333333
return;
334334
}
335335

0 commit comments

Comments
 (0)