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

Retain Hash when included in URL #757

Merged
merged 1 commit into from
Dec 18, 2024
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
2 changes: 1 addition & 1 deletion resources/frontend/js/convertkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function convertKitRemoveSubscriberIDFromURL( url ) {
}

// Update history.
window.history.pushState( null, title, url_object.pathname + params );
window.history.pushState( null, title, url_object.pathname + params + url_object.hash );

}

Expand Down
83 changes: 83 additions & 0 deletions tests/acceptance/general/SubscriberIDURLCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,73 @@ public function testSubscriberIDRemovedFromURL(AcceptanceTester $I)
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'], $I->grabFromCurrentUrl());
$I->assertStringNotContainsString('#', $I->grabFromCurrentUrl());

// Load the Page with UTM parameters at the end.
$I->amOnPage('/convertkit-subscriber-id-url?ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] . '&utm_source=email&utm_medium=email');
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'], $I->grabFromCurrentUrl());
$I->assertStringContainsString('?utm_source=email&utm_medium=email', $I->grabFromCurrentUrl());
$I->assertStringNotContainsString('#', $I->grabFromCurrentUrl());

// Load the Page with UTM parameters at the start.
$I->amOnPage('/convertkit-subscriber-id-url?utm_source=email&utm_medium=email&ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID']);
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'], $I->grabFromCurrentUrl());
$I->assertStringContainsString('?utm_source=email&utm_medium=email', $I->grabFromCurrentUrl());
$I->assertStringNotContainsString('#', $I->grabFromCurrentUrl());
}

/**
* Test that the ck_subscriber_id parameter is removed from the URL
* and that a hash is retained if specified in the URL
*
* @since 2.7.0
*
* @param AcceptanceTester $I Tester.
*/
public function testSubscriberIDRemovedFromURLAndHashRetainedWhenSpecified(AcceptanceTester $I)
{
// Create Page.
$I->havePageInDatabase(
[
'post_name' => 'convertkit-subscriber-id-url-hash',
'post_content' => 'Test',
]
);

// Confirm that a blank ck_subscriber_id does not cause a fatal error.
$I->amOnPage('/convertkit-subscriber-id-url-hash?ck_subscriber_id=#hash');
$I->checkNoWarningsAndNoticesOnScreen($I);

// Confirm that a non-numeric ck_subscriber_id does not cause a fatal error.
$I->amOnPage('/convertkit-subscriber-id-url-hash?ck_subscriber_id=abcde#hash');
$I->checkNoWarningsAndNoticesOnScreen($I);

// Confirm that the ck_subscriber_id was removed.
$I->amOnPage('/convertkit-subscriber-id-url-hash?ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] . '#hash');
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'], $I->grabFromCurrentUrl());
$I->assertStringContainsString('#hash', $I->grabFromCurrentUrl());

// Load the Page with UTM parameters at the end.
$I->amOnPage('/convertkit-subscriber-id-url-hash?ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] . '&utm_source=email&utm_medium=email#hash');
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'], $I->grabFromCurrentUrl());
$I->assertStringContainsString('?utm_source=email&utm_medium=email', $I->grabFromCurrentUrl());
$I->assertStringContainsString('#hash', $I->grabFromCurrentUrl());

// Load the Page with UTM parameters at the start.
$I->amOnPage('/convertkit-subscriber-id-url-hash?utm_source=email&utm_medium=email&ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'] . '#hash');
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('ck_subscriber_id=' . $_ENV['CONVERTKIT_API_SUBSCRIBER_ID'], $I->grabFromCurrentUrl());
$I->assertStringContainsString('?utm_source=email&utm_medium=email', $I->grabFromCurrentUrl());
$I->assertStringContainsString('#hash', $I->grabFromCurrentUrl());
}

/**
Expand Down Expand Up @@ -91,6 +144,36 @@ public function testQuerySeparatorNotAppendedToURLWhenCookieExists(AcceptanceTes
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('?', $I->grabFromCurrentUrl());
$I->assertStringNotContainsString('#', $I->grabFromCurrentUrl());
}

/**
* Test that no query separator is appended to the URL when a valid ck_subscriber_id exists
* and that a hash is retained if specified in the URL
*
* @since 2.7.0
*
* @param AcceptanceTester $I Tester.
*/
public function testQuerySeparatorNotAppendedToURLWhenCookieExistsAndHashRetainedWhenSpecified(AcceptanceTester $I)
{
// Create Page.
$I->havePageInDatabase(
[
'post_name' => 'convertkit-subscriber-id-cookie-hash',
'post_content' => 'Test',
]
);

// Set the ck_subscriber_id cookie.
$I->setCookie('ck_subscriber_id', $_ENV['CONVERTKIT_API_SUBSCRIBER_ID']);

// Confirm that no query parameters does not append a separator/question mark.
$I->amOnPage('/convertkit-subscriber-id-url#hash');
$I->checkNoWarningsAndNoticesOnScreen($I);
$I->wait(2);
$I->assertStringNotContainsString('?', $I->grabFromCurrentUrl());
$I->assertStringContainsString('#hash', $I->grabFromCurrentUrl());
}

/**
Expand Down