-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of TikTok.js to /src/providers and /test/providers. Also add…
…ed TIKTOK16x16.png to src/assets/images/icons and updated icons.scss accordingly
- Loading branch information
1 parent
9387aad
commit 8c08e2a
Showing
4 changed files
with
325 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
/** | ||
* TikTok Tracking Events | ||
* | ||
* | ||
* @class | ||
* @extends BaseProvider | ||
*/ | ||
class TikTokProvider extends BaseProvider { | ||
constructor() { | ||
super(); | ||
this._key = "TIKTOK"; | ||
this._pattern = /business\.topbuzz\.com\/2\/wap\/landing_tetris_log\//; | ||
this._name = "TikTok"; | ||
this._type = "marketing"; | ||
this._keywords = ["TikTok"]; | ||
} | ||
|
||
/** | ||
* Retrieve the column mappings for default columns (account, event type) | ||
* | ||
* @return {{}} | ||
*/ | ||
get columnMapping() { | ||
return { | ||
"account": "track_data[advertiser_id]", | ||
"requestType": "track_data[event_type]" | ||
}; | ||
} | ||
|
||
/** | ||
* Retrieve the group names & order | ||
* | ||
* @returns {*[]} | ||
*/ | ||
get groups() { | ||
return [ | ||
{ | ||
"key": "general", | ||
"name": "General" | ||
}, | ||
{ | ||
"key": "event", | ||
"name": "Event Data" | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* Get all of the available URL parameter keys | ||
* | ||
* @returns {{}} | ||
*/ | ||
get keys() { | ||
return { | ||
"device_id": { | ||
"name": "Device ID", | ||
"group": "general" | ||
}, | ||
"user_id": { | ||
"name": "User ID", | ||
"group": "general" | ||
}, | ||
"uid": { | ||
"name": "UID", | ||
"group": "general" | ||
}, | ||
"ut": { | ||
"name": "UT", | ||
"group": "general" | ||
}, | ||
"client_version": { | ||
"name": "Client Version", | ||
"group": "general" | ||
}, | ||
"version_code": { | ||
"name": "Version Code", | ||
"group": "general" | ||
}, | ||
"req_id": { | ||
"name": "Request ID", | ||
"group": "general" | ||
}, | ||
"cid": { | ||
"name": "Client ID", | ||
"group": "general" | ||
}, | ||
"site_id": { | ||
"name": "Site ID", | ||
"group": "general" | ||
}, | ||
"ad_id": { | ||
"name": "Ad ID", | ||
"group": "general" | ||
}, | ||
"tt_bridge": { | ||
"name": "TikTok Bridge", | ||
"group": "general" | ||
}, | ||
"tt_env": { | ||
"name": "TikTok Environment", | ||
"group": "general" | ||
}, | ||
"app_id": { | ||
"name": "App ID", | ||
"group": "general" | ||
}, | ||
"source": { | ||
"name": "Source", | ||
"group": "general" | ||
}, | ||
"sdk_version": { | ||
"name": "SDK Version", | ||
"group": "general" | ||
}, | ||
"t": { | ||
"name": "Date-Time Stamp", | ||
"group": "general" | ||
}, | ||
"track_data[event_type]": { | ||
"name": "Event Type", | ||
"group": "event" | ||
}, | ||
"track_data[event_pixel_id]": { | ||
"name": "Event Pixel ID", | ||
"group": "event" | ||
}, | ||
"track_data[advertiser_id]": { | ||
"name": "Advertiser ID", | ||
"group": "event" | ||
}, | ||
"track_data[data_type]": { | ||
"name": "Data Type", | ||
"group": "event" | ||
}, | ||
"track_data[options]": { | ||
"name": "Options", | ||
"group": "event" | ||
}, | ||
"track_data[log_extra]": { | ||
"name": "Log Extra", | ||
"group": "event" | ||
}, | ||
"track_data[os]": { | ||
"name": "Operating System", | ||
"group": "event" | ||
}, | ||
"track_data[page_url]": { | ||
"name": "Page URL", | ||
"group": "event" | ||
}, | ||
"track_data[page_type]": { | ||
"name": "Page Type", | ||
"group": "event" | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Parse a given URL parameter into human-readable form | ||
* | ||
* @param {string} name | ||
* @param {string} value | ||
* | ||
* @returns {void|{}} | ||
*/ | ||
handleQueryParam(name, value) { | ||
let result = {}; | ||
if (name === "track_data") { | ||
// do handling in custom | ||
} else { | ||
result = super.handleQueryParam(name, value); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* Parse custom properties for a given URL | ||
* | ||
* @param {string} url | ||
* @param {object} params | ||
* | ||
* @returns {Array} | ||
*/ | ||
handleCustom(url, params) { | ||
let results = [], | ||
eventData = params.get("track_data"), | ||
requestType = "Event"; | ||
|
||
results.push({ | ||
"key": "requestType", | ||
"value": requestType, | ||
"hidden": true | ||
}); | ||
|
||
// Any event-data | ||
if (eventData) { | ||
try { | ||
let data = JSON.parse(eventData); | ||
if (typeof data === "object" && data !== null){ | ||
Object.entries(data).forEach(([key, data]) => { | ||
Object.entries(data).forEach(([key, data]) => { | ||
let result = super.handleQueryParam(`track_data[${key}]`, data); | ||
if (result) { | ||
results.push(result); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
} catch (e) { | ||
results.push({ | ||
"key": "track_event", | ||
"field": "Events", | ||
"value": eventData, | ||
"group": "events" | ||
}); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import test from 'ava'; | ||
|
||
import { default as TikTokProvider } from "../source/providers/TikTok"; | ||
import { OmnibugProvider } from "../source/providers.js"; | ||
|
||
const PIXEL_ID = "TIKTOK"; | ||
|
||
test("TikTokProvider returns provider information", (t) => { | ||
let provider = new TikTokProvider(); | ||
t.is(provider.key, PIXEL_ID, "Key should always be TIKTOK"); | ||
t.is(provider.type, "Marketing", "Type should always be marketing"); | ||
t.true(typeof provider.name === "string" && provider.name !== "", "Name should exist"); | ||
t.true(typeof provider.pattern === 'object' && provider.pattern instanceof RegExp, "Pattern should be a RegExp value"); | ||
}); | ||
|
||
test("TikTokProvider pattern should match Pinterest calls", t => { | ||
let provider = new TikTokProvider(), | ||
urls = [ | ||
"https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22shopping%22%2C%22event_pixel_id%22%3A%226864655820185993221%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:32:31%20GMT-0500%20(Central%20Daylight%20Time", | ||
"https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22form%22%2C%22event_pixel_id%22%3A%226864650693593071621%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:34:46%20GMT-0500%20(Central%20Daylight%20Time)" | ||
], | ||
badUrls = [ | ||
"https://business.topbuzz.com/2/user.js", | ||
"https://business.topbuzz.com/lib/main.123abc.js", | ||
"https://omnibug.io/testing" | ||
]; | ||
|
||
urls.forEach((url) => { | ||
t.true(provider.checkUrl(url)); | ||
}); | ||
|
||
badUrls.forEach((url) => { | ||
t.false(provider.checkUrl(url), "Provider should not match on non-provider based URLs"); | ||
}); | ||
}); | ||
|
||
test("OmnibugProvider returns TikTok", t => { | ||
let url = "https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22form_detail%22%2C%22event_pixel_id%22%3A%226864650693593071621%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:34:46%20GMT-0500%20(Central%20Daylight%20Time)", | ||
results = OmnibugProvider.parseUrl(url); | ||
t.true(typeof results === "object" && results !== null, "Results is a non-null object"); | ||
t.is(results.provider.key, PIXEL_ID, "Results provider is TikTok"); | ||
}); | ||
|
||
test("TikTokProvider returns data", t => { | ||
let provider = new TikTokProvider(), | ||
url = "https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22form_detail%22%2C%22event_pixel_id%22%3A%226864650693593071621%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:34:46%20GMT-0500%20(Central%20Daylight%20Time)", | ||
results = provider.parseUrl(url), | ||
advertiserID = results.data.find((result) => { | ||
return result.key === "track_data[advertiser_id]"; | ||
}), | ||
eventType = results.data.find((result) => { | ||
return result.key === "track_data[event_type]"; | ||
}); | ||
|
||
t.is(typeof advertiserID, "object"); | ||
t.is(advertiserID.field, "Advertiser ID"); | ||
t.is(advertiserID.value, "6864693943246782469"); | ||
|
||
t.is(typeof eventType, "object"); | ||
t.is(eventType.field, "Event Type"); | ||
t.is(eventType.value, "form_detail"); | ||
}); | ||
//TODO: | ||
test("TikTokProvider returns requestType", t => { | ||
let provider = new TikTokProvider(), | ||
downloadDetailURL = "https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22download_detail%22%2C%22event_pixel_id%22%3A%226864654174202642437%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:34:47%20GMT-0500%20(Central%20Daylight%20Time)", | ||
shoppingURL = "https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22shopping%22%2C%22event_pixel_id%22%3A%226864655820185993221%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:34:46%20GMT-0500%20(Central%20Daylight%20Time)", | ||
phoneURL = "https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22phone%22%2C%22event_pixel_id%22%3A%226864656477248913413%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:34:46%20GMT-0500%20(Central%20Daylight%20Time)", | ||
downloadDetailParsed = provider.parseUrl(downloadDetailURL), | ||
shoppingParsed = provider.parseUrl(shoppingURL), | ||
phoneParsed = provider.parseUrl(phoneURL), | ||
downloadDetailResult = downloadDetailParsed.data.find((result) => { | ||
return result.key === "requestType"; | ||
}), | ||
shoppingResult = shoppingParsed.data.find((result) => { | ||
return result.key === "requestType"; | ||
}), | ||
phoneResult = phoneParsed.data.find((result) => { | ||
return result.key === "requestType"; | ||
}); | ||
|
||
t.is(typeof downloadDetailResult, "object"); | ||
t.is(downloadDetailResult.value, "Event"); | ||
|
||
t.is(typeof shoppingResult, "object"); | ||
t.is(shoppingResult.value, "Event"); | ||
|
||
t.is(typeof phoneResult, "object"); | ||
t.is(phoneResult.value, "Event"); | ||
}); | ||
|
||
test("TikTokProvider handles bad data", t => { | ||
let provider = new TikTokProvider(), | ||
url = "https://business.topbuzz.com/2/wap/landing_tetris_log/?device_id=&user_id=&uid=&ut=&client_version=&version_code=&req_id=&cid=&site_id=&ad_id=&track_data=%5B%7B%22event_type%22%3A%22shopping%22%2C%22event_pixel_id%22%3A%226864655820185993221%22%2C%22advertiser_id%22%3A%226864693943246782469%22%2C%22data_type%22%3A2%2C%22options%22%3A%7B%7D%2C%22log_extra%22%3A%22%7B%7D%22%2C%22os%22%3A%22%22%2C%22page_url%22%3A%22https%3A%2F%2Fdigital-intelligence.myshopify.com%2F%22%2C%22page_type%22%3A0%7D%5D&tt_bridge=1111&tt_env=1110&app_id=&source=webunion&sdk_version=s0.0.0.22&t=Wed%20Aug%2026%202020%2023:34:46%20GMT-0500%20(Central%20Daylight%20Time)", | ||
parsed = provider.parseUrl(url), | ||
eventData = parsed.data.find((result) => { | ||
return result.key === "track_data[event_pixel_id]"; | ||
}); | ||
|
||
t.is(typeof eventData, "object"); | ||
t.is(eventData.value, "6864655820185993221"); | ||
}); |