Skip to content
Merged
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 @@ -17,20 +17,29 @@
<div class="page">
<div class="container">
<ng-container *ngIf="isIos">
<section i18n="@@app.texts.platformNotSupported.iosMessage"><strong>Platform Not Supported:</strong> We've detected you're using an iOS device. Currently, <strong>Ground is only available for Android.</strong></section>
<section i18n="@@app.texts.platformNotSupported.iosMessage">
<strong>Platform Not Supported:</strong> We've detected you're using an
iOS device. Currently,
<strong>Ground is only available for Android.</strong>
</section>
</ng-container>

<ng-container *ngIf="!isIos">
<section i18n="@@app.texts.launchingGround">Launching <strong>Ground</strong>...</section>
<section i18n="@@app.texts.launchingGround">
Launching <strong>Ground</strong>...
</section>

<section i18n="@@app.texts.installRedirectMessage">If it doesn't open automatically, you will be redirected to Google Play to install it.</section>
<section i18n="@@app.texts.installRedirectMessage">
If it doesn't open automatically, you will be redirected to Google Play
to install it.
</section>

<section *ngIf="googlePlayId$ | async as googlePlayId">
<a [href]="'https://play.google.com/store/apps/details?id=' + googlePlayId">
<a [href]="playStoreUrl || getPlayStoreUrl(googlePlayId)">
<img
[src]="getItOnGooglePlayImageSrc"
alt="Get in on Google Play"
i18n-alt="@@app.labels.googlePlayBadgeAlt"
[src]="getItOnGooglePlayImageSrc"
alt="Get it on Google Play"
i18n-alt="@@app.labels.googlePlayBadgeAlt"
/>
</a>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Router } from '@angular/router';
import { firstValueFrom } from 'rxjs';

import { AppConfigService } from 'app/services/app-config/app-config.service';
import { SURVEY_SEGMENT } from 'app/services/navigation/navigation.constants';
import { NavigationService } from 'app/services/navigation/navigation.service';

@Component({
Expand All @@ -36,6 +37,7 @@ export class AndroidIntentLandingPageComponent implements OnInit {
getItOnGooglePlayImageSrc: string;
isAndroid = false;
isIos = false;
playStoreUrl = '';

constructor(@Inject(LOCALE_ID) public locale: string) {
const languageId = locale.split('-')[0];
Expand All @@ -62,6 +64,22 @@ export class AndroidIntentLandingPageComponent implements OnInit {
}
}

/**
* Extracts the survey id from an app link path of the form
* `/android/survey/{surveyId}`, ignoring any query string or fragment.
* Returns an empty string when no survey id is present.
*/
getPlayStoreUrl(googlePlayId: string): string {
return this.navigationService.getPlayStoreUrl(googlePlayId);
}

private parseSurveyId(path: string): string {
const segments = path.split(/[?#]/)[0].split('/');
const surveyIndex = segments.indexOf(SURVEY_SEGMENT);

return surveyIndex >= 0 ? (segments[surveyIndex + 1] ?? '') : '';
}

private isAndroidDevice(): boolean {
const userAgent =
window.navigator.userAgent || window.navigator.vendor || 'unknown';
Expand Down Expand Up @@ -91,11 +109,18 @@ export class AndroidIntentLandingPageComponent implements OnInit {

const path = this.router.url;

const surveyId = this.parseSurveyId(path);

this.playStoreUrl = this.navigationService.getPlayStoreUrl(
googlePlayId,
surveyId
);

const timeout = 5000;

// Fallback: redirect to Google Play if app doesn't open
// Fallback: if the app didn't open, redirect to Google Play.
const redirectTimeoutId = setTimeout(() => {
// window.location.href = `https://play.google.com/store/apps/details?id=${googlePlayId}`;
window.location.href = this.playStoreUrl;
}, timeout);

// Try opening the app via intent URL
Expand Down
7 changes: 7 additions & 0 deletions web/src/app/services/navigation/navigation.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@ describe('NavigationService', () => {
'survey/survey123/edit/survey'
);
});

it('getPlayStoreUrl carries the survey id in the install referrer', () => {
expect(service.getPlayStoreUrl('org.ground.app', 'survey123')).toBe(
'https://play.google.com/store/apps/details?id=org.ground.app' +
'&referrer=survey_id%3Dsurvey123'
);
});
});
7 changes: 7 additions & 0 deletions web/src/app/services/navigation/navigation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ export class NavigationService implements OnDestroy {
return `${this.document.location.origin}/${ANDROID_SEGMENT}/${SURVEY_SEGMENT}/${surveyId}`;
}

getPlayStoreUrl(googlePlayId: string, surveyId?: string): string {
const url = `https://play.google.com/store/apps/details?id=${googlePlayId}`;
if (!surveyId) return url;
const referrer = encodeURIComponent(`survey_id=${surveyId}`);
return `${url}&referrer=${referrer}`;
}

getSidePanelExpanded(): boolean {
return this.sidePanelExpanded;
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/locale/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"app.texts.platformNotSupported.iosMessage": "{$START_TAG_STRONG}Platform Not Supported:{$CLOSE_TAG_STRONG} We've detected you're using an iOS device. Currently, {$START_TAG_STRONG}Ground is only available for Android.{$CLOSE_TAG_STRONG}",
"app.texts.launchingGround": "Launching {$START_TAG_STRONG}Ground{$CLOSE_TAG_STRONG}...",
"app.texts.installRedirectMessage": "If it doesn't open automatically, you will be redirected to Google Play to install it.",
"app.labels.googlePlayBadgeAlt": "Get in on Google Play",
"app.labels.googlePlayBadgeAlt": "Get it on Google Play",
"app.labels.loadingSurvey": "Loading survey...",
"app.labels.goToSurvey": "Go to survey",
"app.labels.continue": "Continue",
Expand Down
Loading