Skip to content

Commit

Permalink
SwG Release 0.1.22.243 (ampproject#38553)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbeckthomas authored Nov 18, 2022
1 parent db41c24 commit d5bdbc6
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 80 deletions.
48 changes: 22 additions & 26 deletions third_party/subscriptions-project/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Version: 0.1.22.240 */
/** Version: 0.1.22.243 */
/**
* Copyright 2018 The Subscribe with Google Authors. All Rights Reserved.
*
Expand Down Expand Up @@ -653,10 +653,10 @@ const RE_ALLOWED_TYPES = new RegExp(ALLOWED_TYPES.join('|'));
*/
class PageConfigResolver {
/**
* @param {!Window|!Document|!Doc} winOrDoc
* @param {!Window|!Document|!DocInterface} winOrDoc
*/
constructor(winOrDoc) {
/** @private @const {!Doc} */
/** @private @const {!DocInterface} */
this.doc_ = resolveDoc(winOrDoc);

/** @private {?function((!PageConfig|!Promise))} */
Expand Down Expand Up @@ -693,13 +693,10 @@ class PageConfigResolver {
if (!this.configResolver_) {
return null;
}
let config = this.metaParser_.check();
if (!config) {
config = this.ldParser_.check();
}
if (!config) {
config = this.microdataParser_.check();
}
const config =
this.metaParser_.check() ||
this.ldParser_.check() ||
this.microdataParser_.check();
if (config) {
// Product ID has been found: initialize the rest of the config.
this.configResolver_(config);
Expand Down Expand Up @@ -773,10 +770,10 @@ class TypeChecker {

class MetaParser {
/**
* @param {!Doc} doc
* @param {!DocInterface} doc
*/
constructor(doc) {
/** @private @const {!Doc} */
/** @private @const {!DocInterface} */
this.doc_ = doc;
}

Expand Down Expand Up @@ -813,10 +810,10 @@ class MetaParser {

class JsonLdParser {
/**
* @param {!Doc} doc
* @param {!DocInterface} doc
*/
constructor(doc) {
/** @private @const {!Doc} */
/** @private @const {!DocInterface} */
this.doc_ = doc;
/** @private @const @function */
this.checkType_ = new TypeChecker();
Expand Down Expand Up @@ -915,26 +912,25 @@ class JsonLdParser {

/**
* @param {*} value
* @param {boolean} def
* @param {boolean} defaultValue
* @return {boolean}
*/
bool_(value, def) {
if (value == null || value === '') {
return def;
}
if (typeof value == 'boolean') {
bool_(value, defaultValue) {
if (typeof value === 'boolean') {
return value;
}
if (typeof value == 'string') {

if (typeof value === 'string') {
const lowercase = value.toLowerCase();
if (lowercase == 'false') {
if (lowercase === 'false') {
return false;
}
if (lowercase == 'true') {
if (lowercase === 'true') {
return true;
}
}
return def;

return defaultValue;
}

/**
Expand Down Expand Up @@ -976,10 +972,10 @@ class JsonLdParser {

class MicrodataParser {
/**
* @param {!Doc} doc
* @param {!DocInterface} doc
*/
constructor(doc) {
/** @private @const {!Doc} */
/** @private @const {!DocInterface} */
this.doc_ = doc;
/** @private {?boolean} */
this.access_ = null;
Expand Down
44 changes: 34 additions & 10 deletions third_party/subscriptions-project/swg-gaa.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** Version: 0.1.22.240 */
/** Version: 0.1.22.243 */
/**
* Copyright 2018 The Subscribe with Google Authors. All Rights Reserved.
*
Expand Down Expand Up @@ -567,6 +567,10 @@ const AnalyticsEvent = {
IMPRESSION_SUBSCRIPTION_LINKING_COMPLETE: 40,
IMPRESSION_SUBSCRIPTION_LINKING_ERROR: 41,
IMPRESSION_SURVEY: 42,
IMPRESSION_REGWALL_ERROR: 43,
IMPRESSION_NEWSLETTER_ERROR: 44,
IMPRESSION_SURVEY_ERROR: 45,
IMPRESSION_METER_TOAST_ERROR: 46,
ACTION_SUBSCRIBE: 1000,
ACTION_PAYMENT_COMPLETE: 1001,
ACTION_ACCOUNT_CREATED: 1002,
Expand Down Expand Up @@ -627,7 +631,7 @@ const AnalyticsEvent = {
ACTION_NEWSLETTER_ALREADY_OPTED_IN_CLICK: 1057,
ACTION_REGWALL_OPT_IN_CLOSE: 1058,
ACTION_NEWSLETTER_OPT_IN_CLOSE: 1059,
ACTION_SHOWCASE_REGWALL_SWIG_CLICK: 1060,
ACTION_SHOWCASE_REGWALL_SIWG_CLICK: 1060,
ACTION_TWG_CHROME_APP_MENU_ENTRY_POINT_CLICK: 1061,
ACTION_TWG_DISCOVER_FEED_MENU_ENTRY_POINT_CLICK: 1062,
ACTION_SHOWCASE_REGWALL_3P_BUTTON_CLICK: 1063,
Expand All @@ -638,6 +642,10 @@ const AnalyticsEvent = {
ACTION_SURVEY_SUBMIT_CLICK: 1068,
ACTION_SURVEY_CLOSED: 1069,
ACTION_SURVEY_DATA_TRANSFER: 1070,
ACTION_REGWALL_PAGE_REFRESH: 1071,
ACTION_NEWSLETTER_PAGE_REFRESH: 1072,
ACTION_SURVEY_PAGE_REFRESH: 1073,
ACTION_METER_TOAST_PAGE_REFRESH: 1074,
EVENT_PAYMENT_FAILED: 2000,
EVENT_REGWALL_OPT_IN_FAILED: 2001,
EVENT_NEWSLETTER_OPT_IN_FAILED: 2002,
Expand All @@ -646,6 +654,7 @@ const AnalyticsEvent = {
EVENT_SUBSCRIPTION_LINKING_FAILED: 2005,
EVENT_SURVEY_ALREADY_SUBMITTED: 2006,
EVENT_SURVEY_SUBMIT_FAILED: 2007,
EVENT_SURVEY_DATA_TRANSFER_FAILED: 2008,
EVENT_CUSTOM: 3000,
EVENT_CONFIRM_TX_ID: 3001,
EVENT_CHANGED_TX_ID: 3002,
Expand Down Expand Up @@ -675,6 +684,8 @@ const AnalyticsEvent = {
EVENT_DISABLE_MINIPROMPT_DESKTOP: 3026,
EVENT_SUBSCRIPTION_LINKING_SUCCESS: 3027,
EVENT_SURVEY_SUBMITTED: 3028,
EVENT_LINK_ACCOUNT_SUCCESS: 3029,
EVENT_SAVE_SUBSCRIPTION_SUCCESS: 3030,
EVENT_SUBSCRIPTION_STATE: 4000,
};
/** @enum {number} */
Expand Down Expand Up @@ -1490,8 +1501,11 @@ const POST_MESSAGE_COMMAND_USER = 'user';
/** Error command for post messages. */
const POST_MESSAGE_COMMAND_ERROR = 'error';

/** Button click command for post messages. */
const POST_MESSAGE_COMMAND_BUTTON_CLICK = 'button-click';
/** GSI Button click command for post messages. */
const POST_MESSAGE_COMMAND_GSI_BUTTON_CLICK = 'gsi-button-click';

/** SIWG Button click command for post messages. */
const POST_MESSAGE_COMMAND_SIWG_BUTTON_CLICK = 'siwg-button-click';

/** 3P button click command for post messages. */
const POST_MESSAGE_COMMAND_3P_BUTTON_CLICK = '3p-button-click';
Expand Down Expand Up @@ -2251,14 +2265,24 @@ class GaaMeteringRegwall {
self.addEventListener('message', (e) => {
if (
e.data.stamp === POST_MESSAGE_STAMP &&
e.data.command === POST_MESSAGE_COMMAND_BUTTON_CLICK
e.data.command === POST_MESSAGE_COMMAND_GSI_BUTTON_CLICK
) {
// Log button click event.
logEvent({
analyticsEvent: AnalyticsEvent.ACTION_SHOWCASE_REGWALL_GSI_CLICK,
isFromUserAction: true,
});
}
if (
e.data.stamp === POST_MESSAGE_STAMP &&
e.data.command === POST_MESSAGE_COMMAND_SIWG_BUTTON_CLICK
) {
// Log button click event.
logEvent({
analyticsEvent: AnalyticsEvent.ACTION_SHOWCASE_REGWALL_SIWG_CLICK,
isFromUserAction: true,
});
}
if (
e.data.stamp === POST_MESSAGE_STAMP &&
e.data.command === POST_MESSAGE_COMMAND_3P_BUTTON_CLICK
Expand Down Expand Up @@ -2319,13 +2343,12 @@ class GaaMeteringRegwall {
});
parentElement.appendChild(buttonEl);

// Track button clicks.
buttonEl.addEventListener('click', () => {
function logButtonClicks() {
logEvent({
analyticsEvent: AnalyticsEvent.ACTION_SHOWCASE_REGWALL_SWIG_CLICK,
analyticsEvent: AnalyticsEvent.ACTION_SHOWCASE_REGWALL_SIWG_CLICK,
isFromUserAction: true,
});
});
}

return new Promise((resolve) => {
self.google.accounts.id.initialize({
Expand All @@ -2339,6 +2362,7 @@ class GaaMeteringRegwall {
'theme': 'outline',
'text': 'continue_with',
'logo_alignment': 'center',
'click_listener': logButtonClicks,
});
});
}
Expand Down Expand Up @@ -2474,7 +2498,7 @@ class GaaGoogleSignInButton {
sendMessageToParentFnPromise.then((sendMessageToParent) => {
sendMessageToParent({
stamp: POST_MESSAGE_STAMP,
command: POST_MESSAGE_COMMAND_BUTTON_CLICK,
command: POST_MESSAGE_COMMAND_GSI_BUTTON_CLICK,
});
});
});
Expand Down
Loading

0 comments on commit d5bdbc6

Please sign in to comment.