Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-tag-web): send (authenticated) user ID #1054

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function getProperties(values: GoogleTagPreviewProps, defaultProperties:
break;
}
case "event": {
hidePropertiesIn(defaultProperties, values, ["targetId"]);
hidePropertiesIn(defaultProperties, values, ["targetId", "sendUserID"]);
handleValueTypes(values, defaultProperties);
break;
}
Expand Down
15 changes: 7 additions & 8 deletions packages/pluggableWidgets/google-tag-web/src/GoogleTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ function GoogleTagBasicPageView(props: GoogleTagContainerProps): ReactElement |
return;
}

const configProps = new Map<string, string | boolean>([["send_page_view", false]]);

if (props.sendUserID && window.mx.session.getUserId() !== undefined) {
configProps.set("user_id", window.mx.session.getUserId());
}

// execute config if not yet executed
executeCommand(
"config",
"",
{
send_page_view: false
},
props.targetId.value
);
executeCommand("config", "", Object.fromEntries(configProps), props.targetId.value);

// execute event page_view
executeCommand(
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/google-tag-web/src/GoogleTag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
</propertyGroup>
</properties>
</property>
<property key="sendUserID" type="boolean" required="true" defaultValue="false">
<caption>Share user ID</caption>
<description>Expose the authenticated User ID to uniquely identify individual users in Google Analytics.</description>
</property>
<!-- / Common config options -->

<!-- Advanced config options -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface GoogleTagContainerProps {
widgetMode: WidgetModeEnum;
targetId?: DynamicValue<string>;
parameters: ParametersType[];
sendUserID: boolean;
command: CommandEnum;
eventName: string;
trackPageChanges: boolean;
Expand All @@ -53,6 +54,7 @@ export interface GoogleTagPreviewProps {
widgetMode: WidgetModeEnum;
targetId: string;
parameters: ParametersPreviewType[];
sendUserID: boolean;
command: CommandEnum;
eventName: string;
trackPageChanges: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ declare global {
};
session: {
getSessionObjectId(): string,
getConfig() : { locale: { code: string } }
getConfig() : { locale: { code: string } },
getUserId(): string
}
};
dojo: {
Expand Down
Loading